Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery cross domain request still failing in IE, but using jsonp
    primarykey
    data
    text
    <p>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.</p> <ol> <li>IE9 and jQuery 1.8.1</li> <li>Call is <code>async</code>, <code>jsonp</code> and <code>crossdomain</code>, <code>cache</code> is <code>false</code>. These are the prerequisites I have found. </li> <li>Works in latest Firefox and Chrome.</li> <li><code>jQuery.support.cors</code> is true</li> <li>Even the response header is set: <code>Access-Control-Allow-Origin:*</code> (<a href="https://stackoverflow.com/questions/9485347/jquery-cross-domain-request-response-headers">SO</a>)</li> <li>The returned JSON code would also be correct, have used a checker (also see 3.)</li> </ol> <p>So why is this failing with <strong>Access denied</strong>? Any idea? Could it be because my code is called from within a "JavaScript" library, and not a <code>&lt;script&gt;&lt;/script&gt;</code> tag on the page?</p> <p>What am I missing?</p> <pre><code> // 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" &amp;&amp; !Object.isNullOrUndefined(data)) { ... } }, error: function (xhr, textStatus, errorThrown) { // access denied } }); </code></pre> <p>-- Edit -- based on Robotsushi's comments, some further research ---</p> <ol> <li>Indeed, cannot find <code>XDomainRequest</code> in the jQuery source code (1.8.1)</li> <li>If I do not set cors (<code>jQuery.support.cors = true</code>) I'll end up with a "No Transport" exception.</li> <li>Still wondering why others obviously succeed with IE9 cross domain requests, e.g. here: <a href="https://stackoverflow.com/questions/9170718/jquery-cross-domain-ajax-jsonp-calls-failing-randomly-for-unknown-reasons-in-som?rq=1">jQuery Cross-Domain Ajax JSONP Calls Failing Randomly For Unknown Reasons In Some IE Versions</a></li> <li><p>The way jQuery handles this, seems to be around the code below, but this is not called in my particular case, no idea why?</p> <p>// Bind script tag hack transport jQuery.ajaxTransport( "script", function(s) {</p> <pre><code>// This transport only deals with cross domain requests if ( s.crossDomain ) { </code></pre></li> <li><p>A similar situation here in year 2010: <a href="https://stackoverflow.com/questions/3362474/jquery-ajax-fails-in-ie-on-cross-domain-calls?rq=1">Jquery $.ajax fails in IE on cross domain calls</a> However, this should have been solved by the later jQuery versions.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload