Ajax is not working in firefox and opera

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • benoypaul
    New Member
    • May 2007
    • 28

    Ajax is not working in firefox and opera

    I have the following javascripts which is working in IE, but not working in Firefox and opera.

    [CODE=javascript]var xmlhttp=null;
    function showCustomer(st r)
    {
    xmlhttp=getxmlh ttp();

    if (xmlhttp==null)
    {
    alert("Your Browser does not support AJAX");
    return;
    }

    var url="search.php ";
    url=url+"?q="+s tr;
    url=url+"&sid=" +Math.random();
    xmlhttp.onready StateChange=sta techanged;
    xmlhttp.open('g et',url,false);
    xmlhttp.send(nu ll);


    }

    function statechanged()
    {
    alert("ok");
    if (xmlhttp.readyS tate==4)
    {

    document.getEle mentById("txt") .innerHTML=xmlh ttp.responseTex t;

    }

    }

    function getxmlhttp()
    {
    xmlhttp=null;
    try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest( );
    }
    catch (e)
    {
    // Internet Explorer
    try
    {
    xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
    }
    catch (e)
    {
    xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
    }
    }
    return xmlHttp;
    }[/CODE]


    How to solve this problem.

    Thanks in advance
    Last edited by acoder; Feb 8 '08, 08:25 AM.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN.

    The probable reason why it is not working is that the global variable is "xmlhttp", but when using the XMLHttpRequest object, you have used "xmlHttp" (note the case difference).

    Comment

    • benoypaul
      New Member
      • May 2007
      • 28

      #3
      Originally posted by acoder
      Welcome to TSDN.
      The probable reason why it is not working is that the global variable is "xmlhttp", but when using the XMLHttpRequest object, you have used "xmlHttp" (note the case difference).

      Thanks for the response.

      I have changed all varables as "xmlhttp". But still above problem exists. ie It is working in IE and not in firefox and opera.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Perhaps onreadyStateCha nge should be onreadystatecha nge.

        What error do you get? Check the console for errors or Firebug if you have it.

        Comment

        • benoypaul
          New Member
          • May 2007
          • 28

          #5
          Originally posted by acoder
          Perhaps onreadyStateCha nge should be onreadystatecha nge.

          What error do you get? Check the console for errors or Firebug if you have it.

          Thanks a lot

          My code is working in firefox as well as in opera. I have changed onreadyStateCha nge to onreadystatecha nge .Then it is working in Opera, but not in firefox. . After this , I changed xmlhttp.open('G ET',url,false) to xmlhttp.open('G ET',url,true) .Now it is working IE, Opera and Firefox.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by benoypaul
            Thanks a lot

            My code is working in firefox as well as in opera. I have changed onreadyStateCha nge to onreadystatecha nge .Then it is working in Opera, but not in firefox. . After this , I changed xmlhttp.open('G ET',url,false) to xmlhttp.open('G ET',url,true) .Now it is working IE, Opera and Firefox.
            It's good that you got it working, but how did it work in the other browsers with those mistakes. That last argument makes AJAX asynchronous.

            Comment

            • delhiloves10
              New Member
              • Feb 2008
              • 1

              #7
              Originally posted by benoypaul
              I have the following javascripts which is working in IE, but not working in Firefox and opera.

              var xmlhttp=null;
              function showCustomer(st r)
              {
              xmlhttp=getxmlh ttp();

              if (xmlhttp==null)
              {
              alert("Your Browser does not support AJAX");
              return;
              }

              var url="search.php ";
              url=url+"?q="+s tr;
              url=url+"&sid=" +Math.random();
              xmlhttp.onready StateChange=sta techanged;
              xmlhttp.open('g et',url,false);
              xmlhttp.send(nu ll);


              }

              function statechanged()
              {
              alert("ok");
              if (xmlhttp.readyS tate==4)
              {

              document.getEle mentById("txt") .innerHTML=xmlh ttp.responseTex t;

              }

              }

              function getxmlhttp()
              {
              xmlhttp=null;
              try
              {
              // Firefox, Opera 8.0+, Safari
              xmlHttp=new XMLHttpRequest( );
              }
              catch (e)
              {
              // Internet Explorer
              try
              {
              xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
              }
              catch (e)
              {
              xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
              }
              }
              return xmlHttp;
              }


              How to solve this problem.

              Thanks in advance
              *************** *************** ***

              xmlhttp.open('g et',url,false);

              Replace with

              xmlhttp.open('g et',url,true);

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Hi, welcome to TSDN! Thanks for posting.
                Originally posted by delhiloves10
                *************** *************** ***

                xmlhttp.open('g et',url,false);

                Replace with

                xmlhttp.open('g et',url,true);
                benoypaul managed to solve this, but thanks anyway for pointing out the change required.

                Comment

                • mindvamp
                  New Member
                  • Sep 2008
                  • 1

                  #9
                  Originally posted by benoypaul
                  ...I changed xmlhttp.open('G ET',url,false) to xmlhttp.open('G ET',url,true) .Now it is working IE, Opera and Firefox.
                  Thank you for the info! Was having the same issue and this resolved it for me as well.

                  Comment

                  Working...