55

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.

Ender
  • 27,153
  • 7
  • 30
  • 34
  • 2
    I have the same problem. I have no extensions. I have "log XMLHttpRequests" ticked, and have tried all the suggestions I can find. I have to use firefox + firebug or charles proxy to do all my debugging with ajax. What a pain that chrome doesnt seem to have any support for viewing ajax responses. – John Little Jun 20 '13 at 08:29
  • FYI the requests are also being made from within flash, and the responses are application/json – John Little Jun 20 '13 at 08:34
  • Please, re-accept the correct answer. – T.Todua Dec 13 '20 at 19:13

9 Answers9

87

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.

Masterov
  • 995
  • 5
  • 3
  • 12
    +1 - This should now be the accepted answer. The question is old. – Mike Sep 06 '11 at 18:01
  • 11
    This didnt work for me. i have the XMLHTTPRequest logging enabled, but in the dev tools network XHR Response tab it always displays "This Request has no response data available". It is not possible to see any ajax response in chrome (for me at least). I have to use firebug which displays it fine. – John Little Jun 12 '13 at 12:12
  • 2
    Yes, I only see my AJAX function names. No data – Ben Racicot Mar 26 '14 at 15:35
  • `and will be able to click them to take you to the resources panel` - when I do this I go to CORS OPTION request which is empty (as exceptexd), but data response still has "This Request has no response data available", Unfortunately answer not helped to solve this – Ivan Borshchov Feb 14 '17 at 15:16
  • This does not answer the question. This only shows the request is being made, but in the console. He is trying to view the response data which is saying "There is no data available for this request." – taystack Sep 11 '17 at 22:18
10

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.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
3

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.

Cristian
  • 31
  • 4
  • This fixed the issue for me as well - the missing charset was preventing the data to show up. – nwinkler Oct 01 '13 at 14:18
  • good to know. wish chrome would fix this issue, as there are (other, unrelated toolchain due to OS upgrades) issues with my being able to change the content-type being changed and it's silly that such a simply problem is causing such a big diversion. – Michael Dec 08 '13 at 21:10
  • Unfortunately not helped, I am already using `Content-Type:application/json; charset=utf-8` – Ivan Borshchov Feb 26 '17 at 14:13
2

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.

loislo
  • 14,025
  • 1
  • 28
  • 24
  • 9
    This is not true anymore. See Masterov's response to this question. – Ardee Aram Jun 21 '12 at 00:47
  • Also consider [Fiddler 2](http://fiddler2.com/) - it's a quick install, it's free, and it's easy to use. There is no other app that gives you a more comprehensive and detailed view of *everything* that goes over the wire, any browser, any plugin, even applications. It has rescued me more than once :-) – mindplay.dk May 30 '13 at 18:29
  • 2
    I have no plugings and I always get "This request has no response data" for all my ajax calls. I have to use firefox + firebug instead. Its amazing that chrome have no support for viewing ajax responses. – John Little Jun 20 '13 at 08:30
2

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);
    };
})();
T.Todua
  • 53,146
  • 19
  • 236
  • 237
  • Thanks, this worked for me. I had "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in ..." error – Sašo Kovačič Jun 17 '20 at 15:44
1

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

die();
1

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

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
  • Resource tracking is definitely on. I can see the requests being made, and the headers of those requests, just not the content. (NOTE: this only applies to AJAX requests, and may only apply to ones made in Flash). – Ender Jul 08 '10 at 02:37
  • That's weird. I don't use flash, maybe that's the problem... might be worth it to try a more recent dev build of chrome/chromium if you haven't yet. – Dagg Nabbit Jul 08 '10 at 02:43
0

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

Phillip Senn
  • 46,771
  • 90
  • 257
  • 373
0

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: 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

Community
  • 1
  • 1
Ivan Borshchov
  • 3,036
  • 5
  • 40
  • 62