I am currently utilizing ember 1.5 with grunt-cli
and I would like to make an AJAX call for CORS support using dataType: "JSON"
.
Ember.$.ajax({
type: "GET",
url: App.serverURL + 'logVisit', // callback for jsonP
data : {
'fp': App.fp
},
dataType : "JSON",
success: function(response) {
console.log('DEBUG: visitor has been registered');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("DEBUG jqXHR.responseText : ",jqXHR.responseText);
var response = jqXHR.responseText;
console.log('Failure!');
if(jqXHR.status&&jqXHR.status==400){
// alert(jqXHR.responseText);
var response = $.parseJSON(jqXHR.responseText);
if (response) {
console.log(response.error);
} else {
// This would mean an invalid response from the server - maybe the site went down or whatever...
console.log("DEBUG: Inside jqXHR.status : Something went wrong");
}
} else {
console.log("DEBUG: Something went wrong");
}
}
});
In IE10/11, everything is working fine. However, in IE8/9, it doesn't work properly as it requires XDR object, leading to the following console output:
LOG: DEBUG jqXHR.responseText: undefined
LOG: Failure!
LOG: DEBUG: Something went wrong
Any suggestions or workarounds?
My Request Header:
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:8080
Origin:http://localhost:9000
Referer:http://localhost:9000/
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36
Response headers in browsers other than IE 8/9
Access-Control-Allow-Origin:*
Content-Type:application/json
Date:Wed, 25 Mar 2015 16:01:56 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked