xmlHttpRequest异步调用 [英] xmlHttpRequest Asyncronous calls

查看:165
本文介绍了xmlHttpRequest异步调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我正在编写由其他人编写的代码,如下所示:

Hi there,
I am working on a code that was written by someone else as:

var obj = getXMLHttpRequest(); //the func returns either a xmlHttpRequest or an ActiveX object

 if( obj != null){
     obj.open("GET", "someUrl.aspx?RND=" + rnd, true);
     obj.setRequestHeader("Cache-Control", "no-cache");
     obj.async = false;
 }



我想知道当 open 陈述中的true替换为false时,是否可以删除行''obj.async = false;''.
更改会产生任何后果吗?或者,当我修改 open 语句时,这只是一种冗余.

删除该行的原因是,当有人取消选中IE中的启用本机XMLHTTP支持" 选项时,xmlHttpRequest对象不支持async属性.



I was wondering whether the line ''obj.async = false;'' could be deleted when the true in the open statement replaced with false.

Does the change have any consequences? or it just a redundancy when I modify the open statement.

The reason to remove the line is because the async property is not supported in xmlHttpRequest object when someone unchecks the "Enable native XMLHTTP support" option in IE.

推荐答案

过去一个月IE9中所有挂起的8.4%是由XMLHttpRequest对象通过同步请求阻止UI线程引起的.

至少有两种方式可以编写代码来避免这些挂起.
1.编写代码以异步调用open(根据您的查询)
2.设置超时属性.

首选第一种方法,因为您不会阻塞UI线程.第二个不是最佳选择,因为您仍然会阻止,但是所花费的时间比现在可能要少.
8.4% of all hangs in IE9 in the past month are caused by XMLHttpRequest objects blocking the UI thread with a synchronous request.

There are at least two ways you can write your code to avoid these hangs.
1. Write your code to call open asynchronously (as per your query)
2. Set the timeout property.

The first method is preferred, because you won’t block on the UI thread. The second is less than optimal, because you’ll still block, but for less time than you’re probably doing now.


这篇关于xmlHttpRequest异步调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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