Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-domain AJAX requests with IE9

Cross-domain AJAX requests (made using jQuery 1.7.2) are not performed in IE9 unless the request dataType is set to "jsonp" or "script".

I discovered this issue in framing a request where I did not care about the response and left dataType unspecified (yes, I know I should care about the response).

So, for example, this will work:

$.ajax({
    url: "http://www.google.com",
    type: "GET", // or "POST"
    dataType: 'jsonp'
});

But this won't:

$.ajax({
    url: "http://www.google.com",
    type: "GET" // or "POST"
});

By "work" I mean that I see an HTTP request made in Firebug or F12.

Both requests work in other browsers. Setting jQuery.support.cors = true; does not affect success, nor does setting crossDomain to true nor cache to false (in the AJAX request).

Why should the success of an AJAX request depend on the dataType requested in just IE? I can understand why it would affect my ability to work with any returned data; I also understand that some servers might reject all requests for a certain dataType (but that is apparently not the case here).

like image 453
Jacob Brown Avatar asked Nov 26 '22 10:11

Jacob Brown


1 Answers

This is not a question of datatype but of clearly verifying, in the browser, that the server really wants to answer this query.

By imposing JSONP you force the server to have a very specific answer (including the method call).

Note that there are now other solutions : you can set, on the server, specific headers (see https://developer.mozilla.org/en-US/docs/HTTP_access_control)

like image 193
Denys Séguret Avatar answered Nov 29 '22 04:11

Denys Séguret