XDomainRequest - Get response body on error

I'm having problems with the XDomainRequest handler onerror. When an error occurs, I can't seem to get the body of the HTTP response (via xdr.responseText). Successful requests (200 OK) work fine.

Here is the request:

POST http://localhost/path HTTP/1.1
Accept: */*
Origin: http://localhost
Accept-Language: cs-CZ
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: localhost
Content-Length: 34
Connection: Keep-Alive
Pragma: no-cache

[Data]

And here is the answer:

HTTP/1.1 400 Bad Request
Content-Length: 54
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
Access-Control-Allow-Origin: *
Date: Mon, 30 Apr 2012 20:57:32 GMT

[Data]

Is it possible to get a response body?

+3
source share
1 answer

Unfortunately, it is not possible to get the response body on error. All you can know is a mistake. See my related question here: Is it possible to catch CORS errors?

One possible workaround (if you have control over the server) is to always return HTTP 200, but include an error code in the response body.

+4
source

All Articles