【问题标题】:Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience - warning主线程上的同步 XMLHttpRequest 已被弃用,因为它会对最终用户的体验产生不利影响 - 警告
【发布时间】:2019-12-25 21:51:16
【问题描述】:

我收到此警告,但我不知道该怎么做。

js代码:

var xhttp = new XMLHttpRequest();

subBtn.addEventListener("click",function(){
    var crd = document.createElement("div");
    crd.setAttribute("class", "card");
    crd.innerHTML = inptTxt.value;
    contDiv .appendChild(crd);
    xhttp.onreadystatechange=function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementsByClassName("card").bgColor = JSON.parse(this.responseText).color;          
        }
    };
    xhttp.open("GET","http://api.creativehandles.com/getRandomColor","" ,true);
    xhttp.send(); 
})

我该如何解决这个问题?

【问题讨论】:

  • 您的open() 调用中有一个杂散的,"" 参数

标签: javascript json xmlhttprequest


【解决方案1】:

将开行改为

xhttp.open("GET","http://api.creativehandles.com/getRandomColor",true);

【讨论】:

    猜你喜欢
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 2015-12-20
    相关资源
    最近更新 更多