XHR, responseXML and this

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?=

    XHR, responseXML and this

    say, i've an XHR request :

    req=new XMLHttpRequest( );

    the response handler being specified that way :

    req.onreadystat echange=request Handler;
    (effectively being importHandler) in the page
    <http://thoraval.yvon.f ree.fr/Fixed_layout/import_nodes.xh tmllines
    43/56.

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

    var importHandler=f unction(){
    if (this.readyStat e==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
  • Martin Honnen

    #2
    Re: XHR, responseXML and this

    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 onreadystatecha nge 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 onreadystatecha nge handler does not work
    as expected either.

    --

    Martin Honnen

    Comment

    • =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?=

      #3
      Re: XHR, responseXML and this

      Martin Honnen <mahotrash@yaho o.dewrote:
      Firefox/Mozilla in my view is rather broken in that regard as it sets up
      the function assigned to onreadystatecha nge 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 onreadystatecha nge handler does not work
      as expected either.
      then, I'll stay with req :o

      thanks !

      --
      Une Bévue

      Comment

      • Bjoern Hoehrmann

        #4
        Re: XHR, responseXML and this

        * Une Bévue wrote in comp.lang.javas cript:
        >in the "requestHandler " first i've tried using 'this' as the receiver,
        >for example :
        >
        var importHandler=f unction(){
        if (this.readyStat e==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:bjoern@h oehrmann.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/

        Comment

        • =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?=

          #5
          Re: XHR, responseXML and this

          Bjoern Hoehrmann <bjoern@hoehrma nn.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

          Comment

          Working...