My Ajax cross domain request is failing in IE 9 with "Access denied". I have read through several posts regarding this topic, and AFAIK it should work.
- IE9 and jQuery 1.8.1
- Call is
async
,jsonp
andcrossdomain
,cache
isfalse
. These are the prerequisites I have found. - Works in latest Firefox and Chrome.
jQuery.support.cors
is true- Even the response header is set:
Access-Control-Allow-Origin:*
(SO) - The returned JSON code would also be correct, have used a checker (also see 3.)
So why is this failing with Access denied? Any idea? Could it be because my code is called from within a "JavaScript" library, and not a <script></script>
tag on the page?
What am I missing?
// The code is part of an object's method (prototype)
// code resides in a library "Mylib.js"
$.ajax({
type: 'GET',
url: url,
cache: false,
async: true,
crossdomain: true, // typo, crossDomain, see my answer below
datatype: "jsonp", // dataType
success: function (data, status) {
if (status == "success" && !Object.isNullOrUndefined(data)) { ... }
},
error: function (xhr, textStatus, errorThrown) {
// access denied
}
});
-- Edit -- based on Robotsushi's comments, some further research ---
- Indeed, cannot find
XDomainRequest
in the jQuery source code (1.8.1) - If I do not set cors (
jQuery.support.cors = true
) I'll end up with a "No Transport" exception. - Still wondering why others obviously succeed with IE9 cross domain requests, e.g. here: jQuery Cross-Domain Ajax JSONP Calls Failing Randomly For Unknown Reasons In Some IE Versions
The way jQuery handles this, seems to be around the code below, but this is not called in my particular case, no idea why?
// Bind script tag hack transport jQuery.ajaxTransport( "script", function(s) {
// This transport only deals with cross domain requests if ( s.crossDomain ) {
A similar situation here in year 2010: Jquery $.ajax fails in IE on cross domain calls However, this should have been solved by the later jQuery versions.