最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery.ajax() log the HTTP request - Stack Overflow

programmeradmin0浏览0评论

I have a function that sends an HTTP POST request and i want to log it for debugging purposes. Here is the function:

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);
        }
    });
}

How can i log the whole HTTP POST request (HTTP Header + data), as soon as it is send?

Thanks.

I have a function that sends an HTTP POST request and i want to log it for debugging purposes. Here is the function:

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);
        }
    });
}

How can i log the whole HTTP POST request (HTTP Header + data), as soon as it is send?

Thanks.

Share Improve this question asked Apr 2, 2014 at 13:41 Christos BaziotisChristos Baziotis 6,03517 gold badges62 silver badges80 bronze badges 2
  • If you are using chrome or firefox you can see the request in developper tools. For chrome, just hit Ctrl+Shift+J and open the network tab. – Thomas Commented Apr 2, 2014 at 13:44
  • I don't see my request. I just see in the console tab what i am logging. Isn't there any way to log the request just like i log the response? – Christos Baziotis Commented Apr 2, 2014 at 13:51
Add a comment  | 

1 Answer 1

Reset to default 15

Look for the tab "Network" (not the Console tab) on your Developer Tools (Ctrl+Shift+J) if you are using Chorme, or anythig similar if you are using another browser.

Even after that, if you want to log the XHtmlRequest, you can always do (if your browser supports console.log):

var xhr = $.ajax(...);
console.log(xhr);

Hope I've helped.

发布评论

评论列表(0)

  1. 暂无评论