同步和异步请求之间的区别是什么? (异步=真/假)区别

由网友(闭眼听风)分享简介:异步=假和异步=真,当我使用打开 XMLHtt prequest ?函数的getXML(){如果(window.XMLHtt prequest){// $ C $下IE7 +,火狐,Chrome,歌剧,Safari浏览器XMLHTTP =新XMLHtt prequest();}其他{// code对IE6,IE5XM...

异步=假和异步=真,当我使用打开 XMLHtt prequest

 函数的getXML(){

    如果(window.XMLHtt prequest){// $ C $下IE7 +,火狐,Chrome,歌剧,Safari浏览器
        XMLHTTP =新XMLHtt prequest();
    }
    其他{// code对IE6,IE5
        XMLHTTP =新的ActiveXObject(Microsoft.XMLHTTP);
    }
    xmlhttp.onreadystatechange =测试
    xmlhttp.open(GET,PlanetCafe.xml,真正的);
    xmlhttp.send(空);
}
 

解决方案

Mozilla开发者:同步和异步请求

  

XMLHtt prequest 同时支持同步和异步通信。在一般情况下,然而,异步请求应pferred到同步请求出于性能原因$ P $

     

总之,同步请求阻止code的执行,可以导致内存泄漏和事件。这可能会导致严重的问题。唯一可行的理由使用同步的要求是更容易方便在下载的Web Workers

What is the difference between async=false and async=true, when I am using open method of XMLHttpRequest?

function GetXML() {

    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = test
    xmlhttp.open("GET", "PlanetCafe.xml", true);
    xmlhttp.send(null);
}
操作系统记录

解决方案

Mozilla Developer: Synchronous and Asynchronous Requests

XMLHttpRequest supports both synchronous and asynchronous communications. In general, however, asynchronous requests should be preferred to synchronous requests for performance reasons.

In short, synchronous requests block the execution of code and can leak memory and events. This can cause serious issues. The only viable reason to use synchronous requests is to more easily facilitate downloads within Web Workers.

阅读全文

相关推荐

最新文章