View AJAX response content in Chrome developer tools?

AjaxGoogle ChromeWebkitDeveloper ToolsWeb Developer-Toolbar

Ajax Problem Overview


Traditionally I use FireBug to debug my AJAX requests. It lets you examine both the contents of your request as well as the response that was sent back from the server. (it also notifies you in the console when these occur, which is a useful feature that Chrome seems to lack).

In Chrome, I only seem to be able to view the requests, not the responses. When I try to examine the response the UI just displays "No Content Available" (Developer Tools > Resources > myRequest.php > Content). Do I have to turn something on to make the Chrome developer tools remember these requests?

EDIT: In case it matters, these requests are being made inside a Flash object.

Ajax Solutions


Solution 1 - Ajax

If you are on a dev channel of Google Chrome:

http://www.chromium.org/getting-involved/dev-channel

...you should be able to right-click in the Developer Tools console, and click "Enable XMLHttpRequest logging".

Once it is enabled, you will see the XHR requests in the console, and will be able to click on them to take you to the resources panel, where you'll be able to see the content of an XHR.

Solution 2 - Ajax

What you might be seeing is only the OPTIONS request of a CORS request being treated as an XHR request by Google Chrome inspector. So if you filter by XHR requests, you might only see the initial OPTIONS preflight request, whose response has no content, and get confused because it seems like Chrome is refusing to show the response. Disable the filter and go to the next request for that same URL, which will most likely be the "real" request corresponding to that CORS preflight request.

Solution 3 - Ajax

I encountered the same problem: POST request from flash + JSON response + no response displayed in Chrome inspector. No problem with FF + FireBug though.

Adding charset=utf-8 to Content-Type in the response headers solved the problem for me:

Content-Type: application/json; charset=utf-8

I'm not sure if this is the proper solution for this issue, but at least I'm able to see now the JSON response in Chrome Inspector.

Solution 4 - Ajax

The content of ajax responses is not visible yet if the request is generated by a plugin. There is some chance that this problem will be fixed soon.

Solution 5 - Ajax

Turn on resource tracking, then check the resources tab. Resource tracking seems to work a lot better if you check "always use resource tracking."

Solution 6 - Ajax

I had empty response because the script was sending empty data by

die();

Solution 7 - Ajax

Solution for PHP:

The reason could be that the requested-url (php page) has errors. But as many hostings has disabled the error-output, you need to enable that in requested .php file (put somewhere in the top of file):

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

After that, you will see the response there.


Solution for Front-end responses:

Sometimes, you might do a quick debug if you execute this code in browser console:

(function() {
    var origOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function() {
        this.addEventListener('load', function() {
            console.log(this);
        });
        origOpen.apply(this, arguments);
    };
})();

Solution 8 - Ajax

In the fail callback, the first parameter has a property called responseText.

Solution 9 - Ajax

The reason can be not only in chrome, but also preview can be stopped even by JS code. For example, there is some plugin for Vue.js called vue-resorcese, and it had this issue: https://stackoverflow.com/questions/42172505/chrome-no-response-data-after-options-request I lived with this issue several months until found that question today. Current question never gave an answer, so I now share it here.

Details: this plugin had next code that creates XHR object:

if ('responseType' in xhr && SUPPORTS_BLOB) {
       xhr.responseType = 'blob';
}

This code was ok and preview worked but until some chrome update. Today when I commented this away, preview appeared again! So first, try check your XHR wrapper, may be it has something like this.

It was the rare issue because it was reproduced only with CORS preflight. BTW right clicking on the OPTIONS XHR and REPLAY also showed preview.

there you have it

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEnderView Question on Stackoverflow
Solution 1 - AjaxMasterovView Answer on Stackoverflow
Solution 2 - AjaxRobin GreenView Answer on Stackoverflow
Solution 3 - AjaxCristianView Answer on Stackoverflow
Solution 4 - AjaxloisloView Answer on Stackoverflow
Solution 5 - AjaxDagg NabbitView Answer on Stackoverflow
Solution 6 - AjaxMichal - wereda-netView Answer on Stackoverflow
Solution 7 - AjaxT.ToduaView Answer on Stackoverflow
Solution 8 - AjaxPhillip SennView Answer on Stackoverflow
Solution 9 - AjaxIvan BorshchovView Answer on Stackoverflow