同步和异步请求之间的区别是什么? (异步=真/假) [英] What is the difference between a synchronous and an asynchronous request? (async=true/false)
问题描述
异步=假和异步=真
,当我使用<$ C $的的区别是什么C>打开
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(空);
}
<一个href="https://developer.mozilla.org/en-US/docs/DOM/XMLHtt$p$pquest/Synchronous_and_Asynchronous_Requests"相对=nofollow> 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
.
这篇关于同步和异步请求之间的区别是什么? (异步=真/假)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!