IE page rendering issue (Wait message)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #16
    To make it asynchronous, change line 6 to:
    Code:
    oRequest.open(\"GET\",sURL,true);

    Comment

    • tusovka
      New Member
      • May 2009
      • 23

      #17
      Originally posted by acoder
      To make it asynchronous, change line 6 to:
      Code:
      oRequest.open(\"GET\",sURL,true);
      I tried changing the 3rd argument to (true) from false and my code fails. I still dont know why.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #18
        yes ... you don't use a callback since you rely currently on a sync process ... try the following in addition to the true-param:

        Code:
        oRequest.onreadystatechange = function() {
            if (oRequest.readyState == 4 && oRequest.status == 200)  {
                return(oRequest.responseText);
                //alert(oRequest.responseText);
            } else {
                alert(\"Error executing XMLHttpRequest call!\");
            }
        }
        kind regards

        Comment

        • tusovka
          New Member
          • May 2009
          • 23

          #19
          Here is the output:

          1)First, the tech selector <span> displays --> undefined
          2)Second, I get the alert message -->
          (Error executing XMLHttpRequest call!)

          [code=javascript]

          function*techPa ge(A,*B,*C,*D,* E,*F)*{
          ****var*oReques t*=*new*XMLHttp Request();
          ****var*sURL=*\ "http://\"+self.locatio n.hostname+E+D+ \".php?A=\"+A+\ "&B=\"+B+\"&F=\ "+F;
          ****//alert(sURL);
          ****//document.write( sURL);
          ****oRequest.op en(\"GET\",sURL ,false);
          ****oRequest.se tRequestHeader( \"User-Agent\",navigat or.userAgent);
          ****oRequest.se nd(null)
          ****
          oRequest.onread ystatechange = function() {
          if (oRequest.ready State == 4 && oRequest.status ==200) {
          return(oRequest .responseText);
          //alert(oRequest. responseText);
          } else {
          alert(\"Error executing XMLHttpRequest call!\");
          }
          }
          }
          [/code]

          I also tried to un-comment --> //alert(oRequest. responseText);
          and I also see this alert. That mean, its as if both parts of the code are executed. The ( if) and (else). There is a good possibility I pasted the code in the wrong part.

          Any suggestion are appreciated !

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #20
            ok ... the error alert appears since the readyState changes sometimes from 1 to 2 to 3 to 4 ... while 4 states that the request is complete, so change the code a bit:

            [CODE=javascript]// callback when readyState changes
            oRequest.onread ystatechange = function() {
            // request is complete
            if (oRequest.ready State == 4) {
            // response is ok
            if (oRequest.statu s == 200) {
            alert(oRequest. responseText);
            } else {
            alert(\"Error executing XMLHttpRequest call!\");
            }
            }
            }[/CODE]
            additionally in the open-method the 3rd param should be true.

            what does the alerts say now?

            kind regards

            Comment

            • tusovka
              New Member
              • May 2009
              • 23

              #21
              Gits,

              I will be back at work on Monday and will apply new changes to the code then. I will post the new results then.

              Thanks for your time.
              Tusovka

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #22
                no problem :) ... i'll have a look at it then :) ... have a nice weekend ...

                kind regards,
                gits

                Comment

                • tusovka
                  New Member
                  • May 2009
                  • 23

                  #23
                  Gits,

                  Well I modified the code as you mention in the previous post.

                  [code=javascript]

                  oRequest.open(\ "GET\",sURL,tru e); //used to be false !!!
                  oRequest.setReq uestHeader(\"Us er-Agent\",navigat or.userAgent);
                  oRequest.send(n ull)

                  oRequest.onread ystatechange = function() {
                  if( oRequest.readyS tate == 4 ) {
                  //response is ok
                  if( oRequest.status == 200 ) {
                  //alert( oRequest.respon seText );
                  return(oRequest .responseText);
                  } else {
                  alert(\"Error executing XMLHttpRequest call!\");
                  }
                  }
                  }

                  [/code]

                  Well I know the last alert never executes so that good news. Unfotunatly, both FireFox and IE both behave the same now. The output is: instantaneous population of the <span> container with a message ( undefined ) instead of a selector.

                  Please note I inserted the return( ) myself because if was not mentioned where that line of code should go.

                  Comment

                  • tusovka
                    New Member
                    • May 2009
                    • 23

                    #24
                    Gits,

                    As I was examining the (https://developer.mozilla.org/En/Using_XMLHttpRequest) web page you recommended I found a few varibles I though might me effecting my program.

                    In the online example:

                    Code:
                     var req = new XMLHttpRequest();  
                     req.open('GET', 'http://www.mozilla.org/', true);  
                     req.onreadystatechange = function (aEvt) {  
                       if (req.readyState == 4) {  
                          if(req.status == 200)  
                           dump(req.responseText);  
                          else  
                           dump("Error loading page\n");  
                       }  
                     };  
                     req.send(null);
                    note the function takes a variable!, mine does not? also the (;) at the end of the function definition. I tried adding the (;) still same behavior. Also the use of dump() instead of return. Finally the send(Null) is at the end of all of this.

                    I'm not sure why the difference, but thought I should mention what I have noticed.

                    My pevious post is not posted yet, (Waiting to be approved).

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #25
                      The function doesn't need a parameter and the semi-colon is not required.

                      Move the send to the end. dump() is a user defined function. Your return isn't quite correct, because what does it return to. I would suggest that you change your code where you have:
                      Code:
                      var techinfo=techPage(A, B, C, D);
                      document.getElementById('tech_selector').innerHTML=techinfo;
                      and change that to use the response to set the tech selector, e.g.
                      Code:
                      document.getElementById('tech_selector').innerHTML=oRequest.responseText;
                      in place of the return.

                      Comment

                      • tusovka
                        New Member
                        • May 2009
                        • 23

                        #26
                        I would like to thank everyone who gave advice and made it possible for me to figure out this task. Finally, I got the query message to display in both FF and IE.

                        First, something that is not seen here is a small php code that goes in to my tech.php page. Right after I decipher the URL and pull out the needed variables, the next thing i do is a ---> flush(); <---.

                        Now, going back to my JavaScript function : techPage()
                        1) Note, I'm using the code snippet (Git's) recommended a couple of post above. -->oRequest.statu s == 200 and the readyState == 4....

                        2) I implemented the idea (Acoder) recommended and got rid of the return, and actually loaded the span right here instead of later in my code. But, just to make a note the return worked, how I'm not sure. I still made the change just because it made my code simpler to understand (I think).

                        3) Note that im actually turning on and off the message here instead of another embedded location.

                        4) Finally the readyState ==2 was the trick that made it all work.

                        So it works... Thanks for all your help...


                        [code=javascript]

                        function*techPa ge(A, B, C, D, E, F)*{
                        var*oRequest*=* new*XMLHttpRequ est();
                        var*sURL=*\"htt p://\"+self.locatio n.hostname+E+D+ \".php?A=\"+A+\ "&B=\"+B+\"&F=\ "+F;
                        //alert(sURL);
                        //document.write( sURL);
                        oRequest.open(\ "GET\",sURL,tru e);
                        oRequest.setReq uestHeader(\"Us er-Agent\",navigat or.userAgent);
                        oRequest.send(n ull) ;

                        oRequest.onread ystatechange = function() {
                        if( oRequest.readyS tate == 4 ) { //transaction is complete (4)
                        document.getEle mentById('wait_ message').style .display='none' ; //message OFF
                        if( oRequest.status == 200 ) { //HTTP statues OK
                        document.getEle mentById('tech_ selector').inne r HTML=oRequest.r esponseText;
                        } else {
                        alert(\"Error executing XMLHttpRequest call!\");
                        }
                        }
                        if( oRequest.readyS tate == 2 ) { //loaded = 2
                        document.getEle mentById('wait_ message').style .display='';
                        //during this state display the message (ON)
                        }
                        } //end of function()
                        } //end of techPage()

                        [/code]

                        Comment

                        Working...