Kyle Cureau
Kyle Cureau

Reputation: 19366

Access denied to jQuery script on IE

I have an iframe using the jQuery 1.4.2 script. The same iframe is injected into both http and https sites. The jQuery script is included in the main HTML file as a relative path (e.g., /scripts/jquery-1.4.2.min.js).

When an AJAX call is made, Internet Explorer denies access. The AJAX is calling on another subdomain, but it's using the right protocol. All other browsers work but Internet Explorer gives the following error:

SCRIPT5: Access is denied.
jquery-1.4.2.min.js, line 127 character 344

I heard this error is from cross-domain AJAX calls. But why is IE the only one giving me crap? Is there an IE solution?

Also, this is my AJAX:

 $.ajax({
     url: thisURL,
     dataType: "json",
     data: {cmd : 'getMessage', uurl: urlVar, t: Math.random()},
     success: function(ret){
         callback(ret)
     }
 });

Upvotes: 47

Views: 97193

Answers (10)

Trolloc
Trolloc

Reputation: 21

I changed my JQuery from version 1.10.1 to 1.10.2 and it seems to have solved this problem for me.

Upvotes: 2

AzuraStar
AzuraStar

Reputation: 31

Simply add 'callback=?' on your ajax URL request like here: http://wsvdmeer.blogspot.com.es/2012/08/bugfix-getjson-not-working-in-ie.html

Upvotes: 0

Emmanuel Gleizer
Emmanuel Gleizer

Reputation: 2018

I get this bug (and thus google here) but the reason was very different. So if you don't have cross site and still get this access denied error: double check the value sent
let's say that you affect one of you variable with the bad following expression:

urlVar = $("theID").val // without () this was the error!

[...]ajax call:

data: {cmd : 'getMessage', uurl: urlVar, t: Math.random()},

Google/FF have no problem with this (check what is receive server side...) BUT IE refuse to send this!

Upvotes: 2

Kevinleary.net
Kevinleary.net

Reputation: 9670

This solved the issue gracefully for me:

https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest

Just install/compile after jQuery and before your script and use the $.ajax method as you normally would, the rest is handled behind the automatically.

Upvotes: 9

Jez D
Jez D

Reputation: 1489

It seems that MS is finding its own way of doing things, rather than adopting industry recommendations. I found the solution here:
https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/blob/master/jQuery.XDomainRequest.js

Upvotes: 0

iCoder
iCoder

Reputation: 41

I was facing similar issue. I was using file upload control but it was hidden and I had another element trying to control the file upload and events to upload file in ajax way

try using the file upload control directly. this solved issue in my application.

Upvotes: 2

Furqan Hameedi
Furqan Hameedi

Reputation: 4400

Check the domain you are accessing, following response headers should be there

"Access-Control-Allow-Methods" : "POST, GET, OPTIONS"
"Access-Control-Allow-Origin"  : "http://www.mydomain.com" or "*"

the other domain should allow your script request. One more header to be added to your response is P3P header.

"p3p" : "CP=IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"

it should help you out.

Upvotes: 2

matthieuR42
matthieuR42

Reputation: 194

Have you try to use the lastest of JQuery(> jquery-1.8.0)? Since the version 1.8.0, they solved some IE9's bugs. Perhaps this one too.

http://blog.jquery.com/2012/08/30/jquery-1-8-1-released/

Upvotes: 4

Rafay
Rafay

Reputation: 31033

IE requires you to use XDomainRequest instead of XHR for cross site, you can try something like...

if ($.browser.msie && window.XDomainRequest) {
            // Use Microsoft XDR
            var xdr = new XDomainRequest();
            xdr.open("get", url);
            xdr.onload = function() {
                // XDomainRequest doesn't provide responseXml, so if you need it:
                var dom = new ActiveXObject("Microsoft.XMLDOM");
                dom.async = false;
                dom.loadXML(xdr.responseText);
            };
            xdr.send();
        } else {
            // your ajax request here
            $$.ajax({
                   url: thisURL,
                   dataType: "json",
                   data: {cmd : 'getMessage', uurl: urlVar, t: Math.random()},
                   success: function(ret){
                               callback(ret)
                    }
            });

        }

Reference

http://forum.jquery.com/topic/cross-domain-ajax-and-ie

not sure whether it fits your scenario

xdr = new XDomainRequest(); 
xdr.onload=function()
{
    alert(xdr.responseText);
}
xdr.open("GET", thisUrl); //thisURl ->your cross domain request URL 
//pass your data here
xdr.send([data]); 

you can find some more guidance here

Upvotes: 45

James Becwar
James Becwar

Reputation: 1206

I had a similar problem and the solution for me was to use jsonp instead of json. That way I didn't have to break out a customer version for IE.

You can only do this if the json server host supports the callback request variable or you have access to the server and can add support. Here is a page that helped me understand the process. Its .net mvc focused, but it gives a good over view of the diffrence between json and jsonp.

http://blogorama.nerdworks.in/entry-EnablingJSONPcallsonASPNETMVC.aspx

Upvotes: 2

Related Questions