I've tried everything under the sun and can't get this working.
Trying to get a simple GET request cross domains in IE 8+9.. works fine in Chrome and Firefox and IE10. Tried using XDomainRequest but no dice.. get undefined error.
function RequestWrapper (url, data, error, success, method) {
// IE8 & 9 only Cross domain JSON GET request
if ('XDomainRequest' in window && window.XDomainRequest !== null) {
var xdr = new XDomainRequest(); // Use Microsoft XDR
xdr.open(method, url);
xdr.onload = function () {
var dom = new ActiveXObject('Microsoft.XMLDOM'),
JSON = $.parseJSON(xdr.responseText);
dom.async = false; // I've tried both true and false
if (JSON == null || typeof (JSON) == 'undefined') {
JSON = $.parseJSON(data.firstChild.textContent);
}
success(JSON);
};
xdr.onerror = function () {
error();
}
xdr.send();
}
// Do normal jQuery AJAX for everything else
else {
$.ajax({
url: url,
type: method,
data: data,
dataType: 'json',
success: success,
error: error,
xhrFields: { withCredentials: true }
});
}
}
RequestWrapper(
// URL
'http://myURL',
// Data
null,
// error
function (xhr, status, error) { console.log('error: ' + status); },
// success
function (data) { console.log('success: ' + data); },
// method
'get'
);
EDIT: I tried using jsonp but get a parsererror. Also tried the iecors.js jQuery ajax custom transport (https://github.com/dkastner/jquery.iecors) .. still no dice
<script src="jquery.iecors.js"></script>
<script type="text/javascript">
function RequestWrapper (url, data, error, success, method) {
$.ajax({
url: url,
type: method,
data: data,
dataType: 'jsonp',
success: success,
error: error,
xhrFields: { withCredentials: true }
});
}
RequestWrapper(
// URL
'http://givingimages.pixfizz.com/v1/users/1891548/books.json',
// Data
null,
// error
function (xhr, status, error) { console.log('error: ' + status); },
// success
function (data) { console.log('success: ' + data); },
// method
'get'
);
</script>
Try below code this is basic example its working fine all browsers already i test it.
create ajax.php file
i think this post helpful to you click here to view script