Last active
August 29, 2015 14:21
-
-
Save inter-coder/0f99c04ccd351a12ea2d to your computer and use it in GitHub Desktop.
Collect data of weather conditions with crossdomain JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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