I am making various cross domain ajax calls to various endpoints. This works just fine in Chrome, Firefox and IE 10 and 11 however it is not working in IE8 and IE9. I am getting the following error in the console:
[object Object]{readyState: 0, status: 0, statusText: "No Transport"}
The ajax code I am using is the following:
$.getJSON(url).done(function (data) {
console.log(data);
//Do stuff based on response
}).fail(function (data){
//Do stuff based on response
});
I have tried adding the following due to others saying it might work:
$.support.cors = true;
However I am still receiving the same error.
I have read that IE8 and IE9 do not support ajax calls and that I need to use xdr.
I have tried that as well but am not having any luck the following is the code I tried:
var xdr = new XDomainRequest();
xdr.onload = function () {
console.log(xdr.responseText);
}
xdr.onerror = function () { /* error handling here */ }
xdr.open('GET', url);
xdr.send();
However, this is not working either. It is very possible I am doing something wrong since I have never worked with xdr before.
The console.log is outputting the following:
<!doctype html>
<html lang="en-us">
<head>
<title>SubscriberExists Snapshot of 6/13/2015 12:12:22 AM</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
So, I guess I have a few questions:
Is the onload and onerror the same as the .done and .fail for jquery?
If not how can I do things based off a success or fail response?
Basically if anyone can help me translate the ajax call I am making into the xdr equivalent. I would greatly appreciate the help.