Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling multiple xmlhttp onload event

    Can anybody tell me why the following code is not working.Only the second function-getCusInfo is working.But amazingly if I put only getCusInfo() function,it works.More amazingly if i put any other function like multiple simple alert functions, they work simultaneously onload.
    Code:
    <script type="text/javascript" >
    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          if (oldonload) {
            oldonload();
          }
          func();
        }
      }
    }
    //add body onload events serially
    
    addLoadEvent(getCusName);
    addLoadEvent(getCusInfo);
    addLoadEvent(function() { 
    	    document.body.style.backgroundColor = '#EFDF95'; 
    	}) 
    function getXMLHttp()
    {
    var xmlhttp = false; 
    if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    }
    return xmlhttp;
    }
    
    function getCusName() 
    { 
    //var url="phpdb.php?name="+name+"&city="+city;
    xmlhttp=getXMLHttp();
    xmlhttp.open("GET","customerdb.php",true); 
    xmlhttp.onreadystatechange = updateName;
    xmlhttp.send(null); 
    
    }
    
    function updateName() 
    {  
      if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
      { 
       response=xmlhttp.responseText;
       document.getElementById("showCustomer").innerHTML = response; 
       } 
    }
    
    function getCusInfo()
    {
    xmlhttp=getXMLHttp();
    xmlhttp.open("GET","navigateAjax.php",true); 
    xmlhttp.onreadystatechange = updateCusInfo;
    xmlhttp.send(null); 
    
    }
    
    function updateCusInfo() 
    { 
      if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
      { 
       response=xmlhttp.responseText;
       document.getElementById("navDiv").innerHTML = response; 
      } 
    }
    </script>
    Last edited by tanvirtonu; 06-17-2009 at 08:15 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •