是否有可能中止同步XmlHtt prequest? [英] Is it possible to abort a synchronous XmlHttpRequest?

查看:164
本文介绍了是否有可能中止同步XmlHtt prequest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个JavaScript函数调用异步使用XmlHtt prequest的Web服务。有人问我,使页面呈现之前,此功能完成其工作。

I have written a JavaScript function that asynchronously calls a web service using XmlHttpRequest. I have been asked to make this function finish its work before the page is rendered.

我想我可以让AJAX请求同步,但我不希望这样,使页面挂太久 - 我想后中止的要求,比如1秒如果没有收到回应

I thought I could make the AJAX request synchronous but I don't want this to make the page hang too long - I'd like to abort the request after, say, 1 second if a response isn't received.

是否有可能中止同步XmlHtt prequest?

Is it possible to abort a synchronous XmlHttpRequest?

推荐答案

您不能:

http://www.hunlock.com/blogs/Snippets:_Synchronous_AJAX 赛斯: 同步AJAX(真的SJAX - 同步JavaScript和XML)。是模态,这意味着的JavaScript将停止处理程序,直到结果被从服务器获取而请求处理,浏览器将有效地冻结浏览器对待调用像一个警告框或提示框,只有它不会等待来自用户的输入,但在输入远程服务器

http://www.hunlock.com/blogs/Snippets:_Synchronous_AJAX sais: "Synchronous AJAX (Really SJAX -- Synchronous Javascript and XML) is modal which means that javascript will stop processing your program until a result has been obtained from the server. While the request is processing, the browser is effectively frozen. The browser treats the call like an alert box or a prompt box only it doesn't wait for input from the user, but on input by the remote server"

在浏览器中运行的同步请求时,它会等待,直到它会得到响应。

Once the browser runs the sync request, it will wait until it will get a response.

这篇关于是否有可能中止同步XmlHtt prequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆