JQuery Ajax always throws error using CORS

Just to clarify, as I cannot put enough information in the header ...

I run a cross site and adhere to CORS and everything works. The browser sends a request for parameters, my service responds to a spatter of the headers of the receivers, then the browser receives a 200 response and sends a message. Feel free to skip header exits if you don't need information from them:

Request for initial options:

OPTIONS http://localhost:1837/authentication HTTP/1.1 Host: localhost:1837 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Connection: keep-alive Origin: http://localhost:6879 Access-Control-Request-Method: POST Access-Control-Request-Headers: x-requested-with Pragma: no-cache Cache-Control: no-cache 

Options Answer:

 HTTP/1.1 200 OK Server: ASP.NET Development Server/10.0.0.0 Date: Thu, 30 Jun 2011 09:50:43 GMT X-AspNet-Version: 4.0.30319 Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS Access-Control-Max-Age: 1000 Access-Control-Allow-Headers: CONTENT-TYPE, x-requested-with Access-Control-Allow-Origin: http://localhost:6879 X-AspNetMvc-Version: 3.0 Cache-Control: private Content-Length: 0 Connection: Close 

Mail request:

 POST http://localhost:1837/authentication HTTP/1.1 Host: localhost:1837 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0 Accept: */* Accept-Language: en-gb,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Connection: keep-alive Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://localhost:6879/login Content-Length: 27 Origin: http://localhost:6879 Pragma: no-cache Cache-Control: no-cache username=test&password=test 

Message reply:

 HTTP/1.1 200 OK Server: ASP.NET Development Server/10.0.0.0 Date: Thu, 30 Jun 2011 09:50:43 GMT X-AspNet-Version: 4.0.30319 X-AspNetMvc-Version: 3.0 Set-Cookie: .ASPXAUTH=; domain=localhost; expires=Thu, 30-Jun-2011 10:20:43 GMT; path=/ Cache-Control: private Content-Length: 0 Connection: Close 

Once all this has been completed, the jquery error callback is called with the error status, and xhr contains:

 readyState 0 responseText "" status 0 statusText "error" 

I am a bit puzzled as the answer seems valid and xhr does not even contain a status code. I tried looking in jquery for a complete callback for the same details there. Has anyone seen something like this before? Oh, and I use Firefox, but I tested the same problem in Chrome too :(

+4
source share
1 answer

Your response message still requires the Access-Control-Allow-Origin header (it is required for all CORS responses since HTTP is stateless).

Also regarding error messages, I found that browser responses to CORS errors are not very useful. Hope this will be fixed in the future.

+10
source

All Articles