最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between a synchronous and an asynchronous request? (async=truefalse) - Stack Overflow

programmeradmin3浏览0评论

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);
}

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);
}
Share Improve this question edited Mar 21, 2013 at 15:23 Danny Beckett 20.9k26 gold badges113 silver badges142 bronze badges asked Mar 13, 2013 at 7:39 TheChamppTheChampp 1,4375 gold badges25 silver badges41 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Mozilla Developer: Synchronous and Asynchronous Requests

XMLHttpRequest supports both synchronous and asynchronous munications. 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论