joelforsyth
joelforsyth

Reputation: 1041

Cross-Domain scripting working in every browser except IE8 & 9

I have a site at myapp.myurl.com that is making an ajax request to api.myurl.com. I understand that this is considered "cross-domain." What I don't understand is why the ajax call works in every browser except IE8 and IE9.

Here's the code with details removed.

 $.ajax({
    type: "POST",
    dataType: "json",
    headers: header,
    data: data,
    url: "api.myurl.com/getdata",
    success: function (data) {
    //dostuff
    }
});

Is there anything I can do?

Here's the response when I run the script manually in IE8

{readyState: 0, responseJSON: undefined, status: 0, statusText: "No Transport"}

Here's the response when I run the script manually in Chrome

Object {readyState: 1, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}

And it has the correct JSON response.

Upvotes: 0

Views: 117

Answers (2)

joelforsyth
joelforsyth

Reputation: 1041

I was not able to find a working solution to posting cross domain (ones that included upgrading to a later version of WebAPI weren't possible).

I solved the issue by creating a POST method in the site's controller and then posting to the web API from the server.

Upvotes: 0

Raul Nohea Goodness
Raul Nohea Goodness

Reputation: 2579

IE 8 and 9 have only a partial CORS implementation. They also use a non-standard object called XDomainRequest to to cross-domain requests.

You may need to write some special code to do it, or use a special jquery plugin.

See this other post which describes similar issues. CORS with jQuery and XDomainRequest in IE8/9

Upvotes: 2

Related Questions