473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XHR problem in IE6 (long)

I'm experiencing a very odd problem and it's happening only in IE6. IE7,
Safari, Opera and Firefox are all working properly. What's happening is
that I'm using XHR request responses to update the pages DOM, there appears
to be a conflict and/or race condition that pretty much locks the browser
down for several minutes until one of the requests times out. A huge red
flag stands out to me from the XHR object documentation
(http://msdn.microsoft.com/en-us/libr...(VS.85).aspx):

----------------------------
XMLHttpRequest.open(sMethod, sUrl [, bAsync] [, sUser] [, sPassword])

Performance Note When bAsync is set to false, send operations are
synchronous, and Windows Internet Explorer does not accept input or produce
output while send operations are in progress. Therefore, this setting should
not be used in situations where it is possible for a user to be waiting on
the send operation to complete.
----------------------------

What we are seeing is that when we try to update the DOM after the first
request, that doesn't seem to get to complete (in as much as the new data is
not presented to the user onscreen) before subsequent XHR requests are sent
out. So I guess because IE is prevented from outputting the DOM update from
the first request, it has issues updating/outputting the DOM update from
subsequent requests. Does that sound right to you? It doesn't to me. And
it appears that the issue presents itself only after the first DOM update.
This will be illustrated in the code below.

So consider the following:

This is the function I'm using to get an XHR object, which is working fine
in and of itself across all browsers I've tested on.

function getXHRObject()
{
var oXMLHttp = null;
try
{
oXMLHttp = new XMLHttpRequest;
XHR.getXHRObject = function()
{
return new XMLHttpRequest;
};
}
catch(e)
{
var aMSxml = ['MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP'];
for (var nI = 0; nI < aMSxml.length; nI++)
{
try
{
oXMLHttp = new ActiveXObject(aMSxml[nI]);
XHR.getXHRObject = function()
{
return new ActiveXObject(aMSxml[nI]);
};
break;
}
catch(e)
{
}
}
}
return oXMLHttp;
}

Here is the main process that is causing the lock up; a few things have been
fairly abbreviated and includes only minimum error checking here...

dojo.io.queueBind( { url: pageUrl,
handler: function(type, data, evt)
{
try
{
var childDiv = dojo.byId(divId);
childDiv.innerHTML = data;

var head =
document.getElementsByTagName("head")[0];
aJavascriptIncludes = // Regex here to
pull out all the
//
javascript src= files from the
//
data variable

for (var idx = 0; idx <
aJavascriptIncludes.length; ++idx)
{
var scriptElement =
document.createElement('SCRIPT');

var current = aJavascriptIncludes[idx];
// Pull the source.
var src =
current.match(/src=\"(.*?)\"/i);
if(src != null )
{
xmlhttp = getXHRObject();

if (xmlhttp === null)
{
alert ("Browser does not support
asynchronous HTTP requests");
}
else
{
// Make the call.
xmlhttp.open("GET", src, false);
xmlhttp.send(null);
scriptElement.text =
xmlhttp.responseText;
}
}
// Append to the DOM.
head.appendChild(scriptElement);
}
}
catch (e)
{
alert('Error Data received:\n' + data);
}
}
} );

Please note, and let me stress, that all of the above works perfectly fine
in all the browsers mentioned above. The only browser that seems to have an
issue with it is IE6.

It seems to me that IE6 is locking up somewhere between this line:

childDiv.innerHTML = data;

and these lines

xmlhttp.open("GET", src, false);
xmlhttp.send(null);
scriptElement.text = xmlhttp.responseText;
....
head.appendChild(scriptElement);

Because xmlhttp.send() is preventing output, if IE6 doesn't have the
opportunity to finish updating the DOM to display the innerHTML of the
childDiv object, it just locks up when it tries to append the scriptElement
to the DOM.

One thing I tried (in verifying that it was trying to get the proper JS
files) was to issue an alert() for each file. When I did that, the entire
process ended up working fine and IE6 did not lock up. So I thought that
perhaps I just needed a delay between each send() request. After much
experimentation and testing, it turned out that I only needed a delay after
the innerHTML of the childDiv was updated. When I changed the above code to
what follows:

dojo.io.queueBind( { url: pageUrl,
handler: function(type, data, evt)
{
try
{
var childDiv = dojo.byId(divId);
childDiv.innerHTML = data;

var head =
document.getElementsByTagName("head")[0];

var pauseProcess = setTimeout( function()
{
var dataInfo = data;
aJavascriptIncludes = // Regex here to
pull out all the
//
javascript src= files from the
//
dataInfo variable

for (var idx = 0; idx <
aJavascriptIncludes.length; ++idx)
{
var scriptElement =
document.createElement('SCRIPT');

var current =
aJavascriptIncludes[idx];
// Pull the source.
var src =
current.match(/src=\"(.*?)\"/i);
if(src != null )
{
xmlhttp = getXHRObject();

if (xmlhttp === null)
{
alert ("Browser does not support
asynchronous HTTP requests");
}
else
{
// Make the call.
xmlhttp.open("GET", src, false);
xmlhttp.send(null);
scriptElement.text =
xmlhttp.responseText;
}
}
// Append to the DOM.
head.appendChild(scriptElement);
}
}, 500 );
}
catch (e)
{
alert('Error Data received:\n' + data);
}
}
} );

everything started working again in IE; no lockups occurred, so it's not as
if there were issues in going out, getting the files and then ultimately
appending them to the DOM. So just by waiting 500ms (250ms is what we
testing as being the bare minimum) before starting the requests for the JS
files, all was well. This is why I said earlier that it seemed to me that
the only delay needed was one between updating the childDiv's innerHTML and
the first request. If we reduce the delay to less than 250ms, we've seen
that IE6 is instead locking up when it tries to go out and get the images
that are part of what the innerHTML was set to.

So, what's going on in IE6? Why is it having issues with this and causing a
lock up? Any help and/or advice would be *greatly* appreciated!

thnx,
Christoph

Aug 21 '08 #1
1 1761
Christoph Boget wrote:
I'm experiencing a very odd problem and it's happening only in IE6. IE7,
Safari, Opera and Firefox are all working properly. What's happening is
that I'm using XHR request responses to update the pages DOM, there appears
to be a conflict and/or race condition that pretty much locks the browser
down for several minutes until one of the requests times out. A huge red
flag stands out to me from the XHR object documentation
(http://msdn.microsoft.com/en-us/libr...(VS.85).aspx):

----------------------------
XMLHttpRequest.open(sMethod, sUrl [, bAsync] [, sUser] [, sPassword])

Performance Note When bAsync is set to false, send operations are
synchronous, and Windows Internet Explorer does not accept input or produce
output while send operations are in progress. Therefore, this setting should
not be used in situations where it is possible for a user to be waiting on
the send operation to complete.
----------------------------

What we are seeing is that when we try to update the DOM after the first
request, that doesn't seem to get to complete (in as much as the new data is
not presented to the user onscreen) before subsequent XHR requests are sent
out. So I guess because IE is prevented from outputting the DOM update from
the first request, it has issues updating/outputting the DOM update from
subsequent requests. Does that sound right to you?
In a way. Apparently you missed the "while send operations are *in
progress*" part.
It doesn't to me.
Then you do not understand this technique as much as you think you do.
And it appears that the issue presents itself only after the first DOM update.
This will be illustrated in the code below.
It is illegibly formatted, and refers to a framework that is questionable at
best. Looks like much ado about nothing to me. Because AJAX is a misnomer,
XHR does not necessarily mean an asynchronous request-response chain,
contrary to what the alert() implies.

In fact, as the cited documentation shows, it is possible to establish a
synchronous one. Obviously, this approach has its drawbacks, so if you do
not want them, make asynchronously handled requests instead.
HTH

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 21 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: luke | last post by:
Hi everybody, please, can someone explain me this behaviour. I have the following piece of code: long long ll; unsigned int i = 2; ll = -1 * i; printf("%lld\n", ll);
21
by: Charles Sullivan | last post by:
I maintain/enhance some inherited FOSS software in C which has compiler options for quite a few different Unix-like operating systems, many of which I've never even heard of. It would be...
12
by: Ahmad Jalil Qarshi | last post by:
Hi, I have an integer value which is very long like 9987967441778573855. Now I want to convert it into equivalent Hex value. The result must be 8A9C63784361021F I have used...
2
by: PengYu.UT | last post by:
Hi, In python, triple quote (""") can be used to quote a paragraph (multiple lines). I'm wondering if there is any equivalent in C++. For the following code, I could write the long string in a...
10
by: ratcharit | last post by:
Currently using cosine function in math.h Currently I get: 1 = cos(1e^-7) Is there another way for cos to return value of high accuracy say: 0.999999 = cos(1e^-7)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.