0

我有以下处理 HTTP 请求的代码。但我越来越

错误:InvalidStateError:DOM 异常 11

错误。

if (window.XMLHttpRequest) {
        req_settings = new XMLHttpRequest();
        req_settings.onreadystatechange = processChange;
        req_settings.open("GET", url, true);
        req_settings.send();
    } else if (window.ActiveXObject) {
        req_settings = new ActiveXObject("Microsoft.XMLHTTP");
        if (req_settings) {
            req_settings.onreadystatechange = processChange;
            req_settings.open("GET", url, true);
            req_settings.send();
        }
    } 
    req_settings.onreadystatechange = processChange; 
    req_settings.send();

请帮忙。

4

2 回答 2

0

代码没有意义,你会打电话

req_settings.onreadystatechange = processChange; 
req_settings.send();

两次,它在 if 的内部和外部!把里面的去掉。它也应该使用本机对象。使用图书馆!

于 2013-08-01T03:27:53.693 回答
0

你打电话send()两次,这是无效的。你的代码应该是

if (window.XMLHttpRequest) {
    var req_settings = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    req_settings = new ActiveXObject("Microsoft.XMLHTTP");
} else
    throw "environment does not support ajax";
req_settings.onreadystatechange = processChange;
req_settings.open("GET", url, true);
req_settings.send();
于 2013-08-01T03:29:37.317 回答