XHR, responseXML and this

U

Une Bévue

say, i've an XHR request :

req=new XMLHttpRequest();

the response handler being specified that way :

req.onreadystatechange=requestHandler;
(effectively being importHandler) in the page
<http://thoraval.yvon.free.fr/Fixed_layout/import_nodes.xhtml> lines
43/56.

in the "requestHandler" first i've tried using 'this' as the receiver,
for example :

var importHandler=function(){
if (this.readyState==4){
----------^^^^

this was working fine with Safari 3.1.1, not at all with Firefox 2,
then, i had to use :
if (req.readyState==4){
----------^^^
req being a global var.

does it means i was lucky with Safari or Firefox is faulty ?

because with req as a global doesn't help me when i have to load two
files "simultaneously", for example, an xml one and an xsl to transform
it.

the second request could collapse the first (generally the xml file size
is greater than the xsl one) ???
 
M

Martin Honnen

Une said:
does it means i was lucky with Safari or Firefox is faulty ?

Firefox/Mozilla in my view is rather broken in that regard as it sets up
the function assigned to onreadystatechange as the 'this' object. That
will be fixed in Firefox 3 I think.
On the other hand with IE 5/6 and new ActiveXObject('Msxml2.XMLHTTP')
using the 'this' object in the onreadystatechange handler does not work
as expected either.
 
U

Une Bévue

Martin Honnen said:
Firefox/Mozilla in my view is rather broken in that regard as it sets up
the function assigned to onreadystatechange as the 'this' object. That
will be fixed in Firefox 3 I think.

U're right, i did a quick test with Firefox 3.0.b4 it works with this
....
On the other hand with IE 5/6 and new ActiveXObject('Msxml2.XMLHTTP')
using the 'this' object in the onreadystatechange handler does not work
as expected either.

then, I'll stay with req :eek:

thanks !
 
B

Bjoern Hoehrmann

* Une Bévue wrote in comp.lang.javascript:
in the "requestHandler" first i've tried using 'this' as the receiver,
for example :

var importHandler=function(){
if (this.readyState==4){
----------^^^^

this was working fine with Safari 3.1.1, not at all with Firefox 2,
then, i had to use :
if (req.readyState==4){
----------^^^
req being a global var.

does it means i was lucky with Safari or Firefox is faulty ?

Using `this` in combination with host objects (such as XMLHttpRequest)
is not always covered properly in the relevant specifications and may
indeed be unreliably across implementations. In event handler code the
`this` object should be bount to the current target, the XMLHttpRequest
object in your case, but as you can see, this is not implemented in all
browsers yet.
because with req as a global doesn't help me when i have to load two
files "simultaneously", for example, an xml one and an xsl to transform
it.

You can do that only using multiple XMLHttpRequest objects in which case
this is not a problem. It is incorrect to send a second request until
the first is completed or aborted.
 
U

Une Bévue

Bjoern Hoehrmann said:
You can do that only using multiple XMLHttpRequest objects in which case
this is not a problem. It is incorrect to send a second request until
the first is completed or aborted.

OK, fine, thanks, i see what to do :

ask for the xsl file when getting the response for the xml one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top