Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,
I am working on a code that was written by someone else as:

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


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.
Posted
Updated 1-May-12 9:03am
v5

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900