【发布时间】:2019-07-18 19:28:37
【问题描述】:
如果请求失败,我尝试使用XMLHttpRequestEventTarget.onerror 处理,但它仅适用于异步请求.. 虽然我确实需要同步请求,因为它使代码对我来说更容易并且可以按顺序工作。 代码
const http = new XMLHttpRequest();
const url = 'http://192.168.1.2/';
http.open('get', url, false );
http.onreadystatechange = function ()
{
if(http.readyState === 4)
{
if(http.status === 200)
{
console.log("it worked ")
}
}
}
http.onerror = function () {
console.log("** An error occurred during the transaction");
};
http.send();
【问题讨论】:
标签: javascript ajax asynchronous xmlhttprequest synchronization