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.
Ajax. Ajax is the traditional way to make an asynchronous HTTP request. Data can be sent using the HTTP POST method and received using the HTTP GET method.
The ajax() method is used to perform an AJAX (asynchronous HTTP) request. All jQuery AJAX methods use the ajax() method. This method is mostly used for requests where the other methods cannot be used.
Using developer tool you can check for request and response of the ajax. You can also see console. log(response) where success function is written in ajax function.
jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With