问题
Many time we face issues while working on Asynchronous javascript. We are not sure what request is posted and what respones is obtained.
How to Debug AJAX Requests. Is there a easy way to do that.
回答1:
I'm pretty sure you can track each request if you instanciate a new object for each call:
var oXhr;
oXhr = new XMLHttpRequest();
oXhr.id = (new Date()).getTime(); /* just an example. It might be flawed if you process requests more than once per ms */
oXhr.onreadystatechange = function() {
if (oXhr.readyState == 4 && (oXhr.status == 200)) {
//do your stuff here
console.log(this.id);
}
}
回答2:
The easiest way to see the request and response is as follows:
- Open the website where you want to inspect request and response in chromw.
- Click F12 for chrome extention.
- Click on Network tab.
- Here you will be able to see all request and response. You will also be able to view how much time is taken by each request.
来源:https://stackoverflow.com/questions/16970941/debug-ajax-requests