Created
May 18, 2012 16:28
-
-
Save devfred/2726235 to your computer and use it in GitHub Desktop.
javascript: Cross Domain Request for IE8+
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
// Get weather for charlotte using YQL + Yahoo weather | |
var xdr = new XDomainRequest(); | |
xdr.open("get", "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D'http%3A%2F%2Fxml.weather.yahoo.com%2Fforecastrss%2F28215_f.xml'&format=json"); | |
xdr.onload = function() { | |
// the string now looks like.. json = { ... }; | |
json = 'json = ' + xdr.responseText; | |
// json is now a regular JSON object | |
eval(json); | |
// parse using same function as for jQuery's success event | |
self.draw(json.query.results.item.forecast, $elem); | |
} | |
/* | |
This is insane ... If all the handlers(especially onprogress)aren't set, the xdr in IE9 randomly aborts :( | |
http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/30ef3add-767c-4436-b8a9-f1ca19b4812e | |
*/ | |
xdr.onprogress = function(){}; | |
xdr.onerror = function(){}; | |
xdr.ontimeout = function(){}; | |
xdr.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment