Skip to content

Instantly share code, notes, and snippets.

@inter-coder

inter-coder/weather.js

Last active Aug 29, 2015
Embed
What would you like to do?
Collect data of weather conditions with crossdomain JavaScript
function weatherXdomain(location,callBack){//crossdomain function
var xmlhttp=new XMLHttpRequest();
var url = 'http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('select * from weather.forecast WHERE location="'+location+'"')+'&format=json&callback=cb';
xmlhttp.open("GET",url,false);
xmlhttp.onload=function(){
function cb(d){return d;}//callBack function for returning results from query
callBack(eval(xmlhttp.responseText));
};
xmlhttp.send();
};
var code="USNY0996"//city: "New York",country: "US",region: "NY"
weatherXdomain(code,function(data){
console.log(data);// display object returned from request
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment