Skip to content

Instantly share code, notes, and snippets.

@inter-coder
Last active August 29, 2015 14:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save inter-coder/0f99c04ccd351a12ea2d to your computer and use it in GitHub Desktop.
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