Problem with Ajax javascript

Discussion in 'C#' started by Sleeping Troll, Aug 15, 2008.

  1. #1
    Once function AJAX() is called it cannot be called again.

    
    <script type="text/javascript">
    <!--
    var xmlHttp;
     try
      {  // Firefox, Opera 8.0+, Safari
       xmlHttp=new XMLHttpRequest();
      }
       catch (e)
        {  // Internet Explorer
         try
         {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
         }
          catch (e)
        {
          try
          {
           xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (e)
         {
          alert("Your browser does not support AJAX!");
         }
       }
     }
    function AJAX(Ref,Spec,Elem)
     {
      xmlHttp.onreadystatechange=function()
      {
       if(xmlHttp.readyState==4)
       {
        var oldElem = document.getElementById(Elem);
        oldElem.innerHTML = xmlHttp.responseText;
       }
     }
    ReqStr = "AJAX.php?Ref=" + Ref + "&Spec=" + Spec + "&Elem=" + Elem;
    xmlHttp.open("Get",ReqStr,true);
    xmlHttp.send(null);
    }
    //-->
    </script>
    
    Code (markup):
    http://trollnest.com/bragflags/default.php

    To see behavior, roll over category menu item, works once then never again.

    It is stuck in request loop I believe.
     
    Sleeping Troll, Aug 15, 2008 IP
  2. engager

    engager Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Seems like your javascript does nothing.
    It creates XMLHttpRequest object, calls xmlHttp.open and that's all.
    I see not loop at all here.
    Didn't you forget to handle onreadystatechange event?
    Usually one assigns handler function to this event to process received data.

    function stateUpdateChanged() {
    alert('Data received: ' + xmlHttp.responseText);
    }

    xmlHttp.onreadystatechange=stateUpdateChanged;
     
    engager, Aug 15, 2008 IP
  3. engager

    engager Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    By the way. I visitied link you gave. In my Opera browser everything works fine.
     
    engager, Aug 15, 2008 IP
  4. engager

    engager Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    See Javascript output console. May be there are some errors there.
     
    engager, Aug 15, 2008 IP