调试Ajax请求 [英] Debug AJAX Requests

查看:95
本文介绍了调试Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多时候,我们面临的问题,当工作在异步JavaScript。我们不知道什么请求被提交并获得什么阶跃响应。

Many time we face issues while working on Asynchronous javascript. We are not sure what request is posted and what respones is obtained.

如何调试Ajax请求。有没有一种简单的方法来做到这一点。

How to Debug AJAX Requests. Is there a easy way to do that.

推荐答案

我是pretty的肯定,如果你的实例化的每个调用一个新的对象的,你可以跟踪每个请求:

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

这篇关于调试Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆