jQuery.ajax()记录HTTP请求 [英] jQuery.ajax() log the HTTP request
问题描述
我有一个发送HTTP POST请求的功能,我想将其记录下来以进行调试.功能如下:
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);
}
});
}
发送后,如何记录整个HTTP POST请求(HTTP标头和数据)?
How can i log the whole HTTP POST request (HTTP Header + data), as soon as it is send?
谢谢.
推荐答案
查找"网络"标签(不是"控制台"标签)(如果您使用的是Chorme,请在开发人员工具(Ctrl + Shift + J)上);如果您使用的是其他浏览器,请使用类似的图形.
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.
即使在那之后,如果您想记录XHtmlRequest,也可以随时执行(如果您的浏览器支持console.log):
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);
希望我有所帮助.
这篇关于jQuery.ajax()记录HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!