3

I tried everything I found on Google to make it work, but without a success.

I'm trying to call an HTTP request to a server on a different domain.
On all browser it works, even on IE10. But, on IE9 and lower it doesn't seems to work correctly.
On IE9 and lower, it sends only the header without a body on all methods.

I'm using jQuery to make the AJAX call, the call can be called from a different domain (actually it can be from any domain).
A JavaScript example :

$.ajax({
    url: "http://api.domain.com/path",
    type: "POST",
    crossDomain: true,
    cache: false,
    data: JSON.stringify({data:"some body data in a json format"}),
    dataType: "json",
    contentType: "application/json",
    success: function(data, textStatus, jqXHR){
        console.log("Response data: ", data, textStatus, jqXHR);
    },
    error: function(jqXHR, textStatus, errorThrown){
        console.error("AJAX error: ", jqXHR, textStatus, errorThrown);
    }
});

Request on IE9:

POST /path HTTP/1.1
Origin: http://[some domain]
Accept-Language: en-GB
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: api.domain.com
Content-Length: 0
DNT: 1
Connection: Keep-Alive
Cache-Control: no-cache
Accept: */*

[no request body]

The response from the server is:

HTTP/1.1 500 Internal Server Error
Server: MochiWeb/1.1 WebMachine/1.9.2 (someone had painted it blue)
Date: Mon, 17 Jun 2013 11:24:26 GMT
Content-Type: text/html
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

I'm using the jQuery.XDomainRequest plugin, but it doesn't helps.
I'm also set jQuery.support.cors = true;, but it doesn't helps either.
I thing it's important to mention that on IE10 it sends an OPTIONS request before the POST request, when on IE9 just POST request.

Any suggestions?

Slavik Meltser
  • 9,712
  • 3
  • 47
  • 48

1 Answers1

0

I am not aware with this jQuery plugin. But sending ajax post to cross domain is a security concern. So browser does not support this. It's amazing how you can manage posting data to other domain.

Below link might be helpful Why the cross-domain Ajax is a security concern?

Community
  • 1
  • 1
Amit Kumar Sharma
  • 262
  • 1
  • 4
  • 12