在Chrome开发者工具中查看AJAX响应内容?

发布于 2024-09-08 06:48:14 字数 277 浏览 3 评论 0原文

传统上我使用 FireBug 来调试 AJAX 请求。它允许您检查请求的内容以及从服务器发回的响应。 (当发生这些情况时,它还会在控制台中通知您,这是 Chrome 似乎缺乏的有用功能)。

在 Chrome 中,我似乎只能查看请求,而不能查看响应。当我尝试检查响应时,UI 仅显示“无可用内容”(开发人员工具 > 资源 > myRequest.php > 内容)。我是否必须打开某些功能才能让 Chrome 开发者工具记住这些请求?

编辑:以防万一,这些请求是在 Flash 对象内发出的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

平生欢 2024-09-15 06:48:14

如果您使用 Google Chrome 的开发频道:

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

...您应该能够在开发人员工具控制台中右键单击,然后单击“启用 XMLHttpRequest 日志记录”。

启用后,您将在控制台中看到 XHR 请求,并且可以单击它们将您带到资源面板,您可以在其中查看 XHR 的内容。

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.

九命猫 2024-09-15 06:48:14

您可能看到的只是 CORS 请求的 OPTIONS 请求被 Google Chrome 检查器视为 XHR 请求。因此,如果您按 XHR 请求进行过滤,您可能只会看到最初的 OPTIONS 预检请求,其响应没有内容,并且会感到困惑,因为 Chrome 似乎拒绝显示响应。禁用过滤器并转到同一 URL 的下一个请求,这很可能是与 CORS 预检请求相对应的“真实”请求。

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.

木緿 2024-09-15 06:48:14

我遇到了同样的问题:来自 flash 的 POST 请求 + JSON 响应 + Chrome 检查器中没有显示响应。不过FF + FireBug 没问题。

将 charset=utf-8 添加到响应标头中的 Content-Type 解决了我的问题:

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

我不确定这是否是此问题的正确解决方案,但至少我现在能够在 Chrome Inspector 中看到 JSON 响应。

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.

牛↙奶布丁 2024-09-15 06:48:14

如果请求是由插件生成的,则 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.

热情消退 2024-09-15 06:48:14

PHP 的解决方案:

原因可能是请求的 url(php 页面)有错误。但由于许多主机已禁用错误输出,您需要在请求的 .php 文件中启用该错误输出(放在文件顶部的某个位置):

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

之后,您将请参阅那里的回复。


前端响应的解决方案:

有时,如果在浏览器控制台中执行以下代码,您可能会进行快速调试:

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

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);
    };
})();
小清晰的声音 2024-09-15 06:48:14

打开资源跟踪,然后检查资源选项卡。如果您选中“始终使用资源跟踪”,资源跟踪似乎会工作得更好。

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

双手揣兜 2024-09-15 06:48:14

我有空响应,因为脚本发送空数据

die();

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

die();
南风起 2024-09-15 06:48:14

在失败回调中,第一个参数有一个名为responseText的属性。

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

日久见人心 2024-09-15 06:48:14

原因不仅是在chrome中,而且甚至可以通过JS代码来停止预览。例如,有一个名为 vue-resorceseVue.js 插件,它有这个问题:
Chrome,OPTIONS 请求后没有响应数据?
我在这个问题上生活了几个月,直到今天发现了这个问题。目前的问题从未给出答案,所以我现在在这里分享。

细节:
该插件有下一个创建 XHR 对象的代码:

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

该代码正常并且预览有效,但直到一些 chrome 更新。
今天当我评论掉这个的时候,预览又出现了!首先,尝试检查您的 XHR 包装器,可能它有类似的内容。

这是一个罕见的问题,因为它只能通过 CORS 预检来重现。顺便说一句,右键单击 OPTIONS XHRREPLAY 也显示预览。

给你了

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文