Debug AJAX Requests [closed]

故事扮演 提交于 2020-01-11 08:24:23

问题


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:

  1. Open the website where you want to inspect request and response in chromw.
  2. Click F12 for chrome extention.
  3. Click on Network tab.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!