A simpler way:
Detect IE:
function detectIE() {
var ua = window.navigator.userAgent,
msie = ua.indexOf('MSIE '),
trident = ua.indexOf('Trident/'),
edge = ua.indexOf('Edge/');
if (msie > 0) {return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);}
if (trident > 0) {var rv = ua.indexOf('rv:');return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);}
if (edge > 0) {return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);}
return false;
}
Differentiate XMLhttp and XDomain:
var url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%27pune%2Cmh%27)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithke"
if (window.XDomainRequest && detectIE()) {
var xdr = new XDomainRequest();
xdr.open("GET", url, false);
xdr.onload = function () {
var res = JSON.parse(xdr.responseText);
if (res == null || typeof (res) == 'undefined')
{
res = JSON.parse(data.firstChild.textContent);
}
publishData(res);
};
xdr.send();
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200 || xmlhttp.status == 304) {
publishData(JSON.parse(xmlhttp.responseText));
} else {
setTimeout(function(){ console.log("Request failed!") }, 0);
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function publishData(data){
console.log(data); //Response
}
Full Example can be found here