When debugging AJAX calls in our web-applications we often dump variables server-side and abort/exit the request, this outputs the values as HTML and sets the response as text/html. However the preview in the network tab tries to parse the response as JSON, making it unreadable.
If we set the Status Code to be an error such as 503 (or any other errorcode), the response is properly parsed as HTML.
I would like to add that this has been working for a long time, and stopped working a while ago - maybe a month.
An example request:
Remote Address: *snip*
Request URL: *snip*
Request Method:POST
Status Code:200 OK
Request Headers
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,nb;q=0.6,da;q=0.4
Connection:keep-alive
Content-Length:407
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie: *snip*
Host: *snip*
Origin: *snip*
Referer: *snip*
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data
argumentCollection:{"model":{"name":"","email":"","title":"","mobile":"","oldpassword":"","password":"","passwordrepeat":"","id":0,"accessRules":[2,8,11,13,14,10]},"options":{}}
method:update
returnformat:json
vfAjax:1
Response Headers
Content-Encoding:gzip
Content-Type:text/html; charset=UTF-8
Date:Wed, 25 Feb 2015 09:12:38 GMT
Server:Microsoft-IIS/7.5
Transfer-Encoding:chunked
Vary:Accept-Encoding
Will show this in preview:
Is this intended behavior? I know the request headers states that application/json, text/javascript should be returned, but I would argue that the response headers should override how it should be previewed in the preview tab.
As you can see when the response has a 503 status code, the preview is shown correctly:
Remote Address: *snip*
Request URL: *snip*
Request Method:POST
Status Code:200 OK
Request Headers
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,nb;q=0.6,da;q=0.4
Connection:keep-alive
Content-Length:407
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie: *snip*
Host: *snip*
Origin: *snip*
Referer: *snip*
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data
argumentCollection:{"model":{"name":"","email":"","title":"","mobile":"","oldpassword":"","password":"","passwordrepeat":"","id":0,"accessRules":[2,8,11,13,14,10]},"options":{}}
method:update
returnformat:json
vfAjax:1
Response Headers
Content-Encoding:gzip
Content-Type:text/html; charset=UTF-8
Date:Wed, 25 Feb 2015 09:12:38 GMT
Server:Microsoft-IIS/7.5
Transfer-Encoding:chunked
Vary:Accept-Encoding
While it is not a huge overhead to have to set the response headers when debugging, it would be much easier if it was not required.
Thanks