jQuery.ajax()记录HTTP请求

Chr*_*tis 6 javascript ajax jquery logging httprequest

我有一个发送HTTP POST请求的函数,我想记录它以进行调试.这是功能:

function serverRequest(URL, DATA, callback) {
    $.ajax({
        url: URL,
        type: "POST",
        dataType: "text",
        contentType: "text/xml",
        processData: false,
        data: DATA,
        success: function (response) {
            console.log(response);
            callback(response);
        },
        error: function (response) {
            console.log(response);
            callback(null);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

如何发送,我如何记录整个HTTP POST请求(HTTP标头+数据)?

谢谢.

Wal*_*ira 10

寻找标签" 网络 "(不是控制台上的开发工具(按Ctrl + Shift + J)选项卡)如果你正在使用Chorme,或anythig类似的,如果你使用的是其他浏览器.

即使在那之后,如果你想记录XHtmlRequest,你总是可以做(如果你的浏览器支持console.log):

var xhr = $.ajax(...);
console.log(xhr);
Run Code Online (Sandbox Code Playgroud)

希望我帮了.

  • fwiw `console.log(xhr);` 打印 `[object Object] (2认同)