Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with HTTPS Ajax Request In IE (Not Crossdomain)

I'm stumped on an issue I'm having with an HTTPS Ajax call in IE only. IE seems to think I'm making a crossdomain request, but I'm not. The following code is called from the page https://mydomain/customer_profile.php:

$.ajax({
    type: 'post',
    url: 'https://mydomain/ajax/retrieve_transaction_details.php',
    data: /* my data is here */,
    success: function(response){
        // do something with the response
    },
    error: function (xhr, ajaxOptions, thrownError){
        alert(xhr.status);
        alert(thrownError);
    }
});

This request works just fine in every browser except IE. In IE, the error function returns "Error: Access is denied". Like I said, I'm completely stumped on this, so any insight or ideas would be great.

like image 659
Jim D Avatar asked Jan 27 '12 16:01

Jim D


People also ask

Does Internet Explorer support ajax?

Browsers that support web apps using Ajax:Microsoft Internet Explorer (IE) for Windows version 5.0 and above, with ActiveX enabled.

What is Crossdomain in ajax?

For a successful cross-domain communication, we need to use dataType “jsonp” in jquery ajax call. JSONP or “JSON with padding” is a complement to the base JSON data format which provides a method to request data from a server in a different domain, something prohibited by typical web browsers.

How do you resolve cross origin issues in ajax?

Re: CORS issue after ajax post requestYour server needs to not only allow POSTs from the origin using Access-Control-Allow-Origin (origin = your Marketo LP domain including protocol, like https://pages.example.com), it also needs to allow the Content-Type header using Access-Control-Allow-Headers.


2 Answers

I guess you are using the <base> tag inside the head section of your HTML; right?

If it is pointing to http instead of https, that would break IE.

like image 78
Nate Avatar answered Oct 11 '22 09:10

Nate


try setting crossDomain to true in your request like this:

$.ajax({
    type: 'post',
    url: 'https://mydomain/ajax/retrieve_transaction_details.php',
    data: /* my data is here */,
    crossDomain: true,
    success: function(response){
        // do something with the response
    },
    error: function (xhr, ajaxOptions, thrownError){
        alert(xhr.status);
        alert(thrownError);
    }
});

this should allow you to make the request regardless of whether it is cross-domain or not.

like image 2
Phil W Avatar answered Oct 11 '22 09:10

Phil W