javascript - 网络错误 : XMLHttpRequest Exception 101

标签 javascript ajax google-chrome xmlhttprequest

我在 Chrome 中遇到 AJAX 问题,出现以下错误:

Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101

这是我的代码:

function IO(filename) {
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        xmlhttp = new XMLHttpRequest();

    } else if (window.ActiveXObject) { // IE
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }

    xmlhttp.open("GET", filename+"?random="+Math.floor(Math.random()*100000001), false);
    xmlhttp.send();

    if(xmlhttp.readyState==4)
        return xmlhttp.responseXML;
}

最佳答案

解决方案是将 async 参数设置为 true:

xmlhttp.open("GET", filename+"?random="+Math.floor(Math.random()*100000001), true);

关于javascript - 网络错误 : XMLHttpRequest Exception 101,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6965942/

相关文章:

javascript - 像参数一样附加到脚本 url 的这个数字是什么?

javascript - 制作一个简单的实时图表

php - 使用 MYSQL、PHP 和 AJAX 的慢速代码

css - 字体在 Chrome 上不起作用

javascript - NodeJS - 如何在不使用外部数据库的情况下管理用户名和任务管理?

javascript - 如何将 Promise 方法转换为 Angular 10 中的 rxjs Observables

javascript - 列出对象中的所有变量名

javascript - 单击 UL LI 时无法更改 DIV 文本

javascript - 我不明白 AJAX 回调

google-chrome - Chrome - 窗口宽度/高度未出现在开发人员模式中?