By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,702 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,702 IT Pros & Developers. It's quick & easy.

XHR, responseXML and this

P: n/a
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.xhtmllines
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) ???

--
Une Bévue
Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Une Bévue wrote:
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2

P: n/a
Martin Honnen <ma*******@yahoo.dewrote:
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 :o

thanks !

--
Une Bévue
Jun 27 '08 #3

P: n/a
* 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.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 27 '08 #4

P: n/a
Bjoern Hoehrmann <bj****@hoehrmann.dewrote:
>
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.
--
Une Bévue
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.