Ajax problem in firefox 3.0.5

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raknin
    New Member
    • Oct 2007
    • 82

    Ajax problem in firefox 3.0.5

    Hi,

    I had a strange problem with firefox ver 3.0.5 that doesn't occur in IE6, opera 9.63 nor in Safari 3.2.1 the problem is that when I call the function GetXmlHttpObjec t (The function is displays below) nothing is happening. The function should insert a listbox in a div. It works for me in the past in firefox 2.0 but now it was stop working.
    The error that I got is:

    document.getEle mentById(countr yLisboxID) is null

    Line 105

    I try to debug it and I found that it doesn't enter the function " xmlHttp.onready statechange = function() " at all. What can be the reason.
    on the other hand when I look at the fiebug I see that I got the desire list box from the server with all the values. Can anyone advise about it.


    Code:
    function GetXmlHttpObject(divID,url)
    {
    
        xmlHttp=XmlHttpObject();
      
        if (xmlHttp==null)
        {
            alert("Your browser does not support AJAX!");
            return FALSE;
        }          
       xmlHttp.onreadystatechange = function() 
       {
         if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
         {  
            document.getElementById(divID).innerHTML=xmlHttp.responseText;
         }
       }
         xmlHttp.open("GET", url,false); 
         xmlHttp.send(null);
         
    }
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    this call:

    [CODE=javascript]xmlHttp.open("G ET", url, false); [/CODE]
    makes the request sync and i think that avoids to fire the onreadystatecha nge-event try to make a async-call:

    [CODE=javascript]xmlHttp.open("G ET", url, true); [/CODE]
    kind regards

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5388

      #3
      note: for sync/async requests with FF/Mozilla you may also use the onload and onerror handlers that will be fired even with sync requests ...

      Comment

      • raknin
        New Member
        • Oct 2007
        • 82

        #4
        Thanks Gits the problem was solved

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5388

          #5
          glad to hear that you got it working ... perhaps you could tell which solution you implemented ... so that other users might find help in case they have a similar problem and find this thread?

          kind regards,
          gits

          Comment

          • raknin
            New Member
            • Oct 2007
            • 82

            #6
            The change i did in the code

            The final function is as following:

            For synchronous mode:

            Code:
             
             function GetXmlHttpObject(divID,url)
             {
                 xmlHttp=XmlHttpObject();
                 if (xmlHttp==null)
                 {
                     alert("Your browser does not support AJAX!");
                     return FALSE;
                 }
                xmlHttp.onreadystatechange = function()
                {
                  if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
                  {
                     document.getElementById(divID).innerHTML=xmlHttp.responseText;
                  }
                }
                  xmlHttp.open("GET", url,true);
                  xmlHttp.send(null);
             }
            For asynchronous mode:

            Code:
             
             function GetXmlHttpObject(divID,url)
             {
                 xmlHttp=XmlHttpObject();
                 if (xmlHttp==null)
                 {
                     alert("Your browser does not support AJAX!");
                     return FALSE;
                 }
                  xmlHttp.open("GET", url,false);
                  xmlHttp.send(null);
                 document.getElementById(divID).innerHTML=xmlHttp.responseText;
             }

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5388

              #7
              thanks for sharing the solution ... just a note: i think it's the other way around so the first is the async case and the second the sync one ...

              kind regards
              gits

              Comment

              Working...