FF/Chrome 中支持的 XMLHttpRequest.DONE 值的问题 [英] Problem with XMLHttpRequest.DONE values supported in FF / Chrome

查看:34
本文介绍了FF/Chrome 中支持的 XMLHttpRequest.DONE 值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段 Javascript 需要调试:

I have a snippet of Javascript that I need to debug:

var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
    if (this.readyState === XMLHttpRequest.DONE) {
        if (this.status === 200) {
            success = true;
        }
    }
};

逐步浏览 Chrome 和 Firefox,我发现第一个if"是正在失败.我可以看到 this.readyState 设置为 1,根据 W3C 规范判断,这应该意味着 OPENED.但是 XMLHttpRequest.DONE 在 Firebug 中显示为 undefined 而不是 4.

Stepping through on Chrome and Firefox, I have found that the first "if" is failing. I can see that this.readyState is set to 1, which judging by the W3C spec should mean OPENED. However XMLHttpRequest.DONE shows as undefined rather than 4 in Firebug.

http://www.w3.org/TR/XMLHttpRequest/#states

Firefox 和 Chrome 中是否存在不支持这些值的问题?

Is there a problem in Firefox and Chrome whereby these values are not supported?

推荐答案

您应该根据数值之一检查 readyState,在您的情况下为 4.

You should be checking readyState against one of the numeric values, 4 in your case.

这篇关于FF/Chrome 中支持的 XMLHttpRequest.DONE 值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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