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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Exclamation It Fails when I use 2 AJAX in one script...

    Hi,

    I am using two almost same scripts in the same page. Here is the all script:

    PHP Code:
    <div id="header2">
    asd
    </div>
    <!-- 
    pradzia -->
    <
    script language="javascript" type="text/javascript">
    <!-- 
    // Get the HTTP Object
    function gethttpObject(){
       if (
    window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
       else if (
    window.XMLHttpRequest) return new XMLHttpRequest();
       else {
          
    alert("Your browser does not support AJAX.");
          return 
    null;
       }
    }   
    // Change the value of the outputText field
    function setOutput(){
        if(
    httpObject2.readyState == 4){
            
    document.getElementById('online').innerHTML httpObject2.responseText;
        }
     
    }
     
    // Implement business logic    
    function doWork(){    
        
    httpObject2 gethttpObject();
        if (
    httpObject2 != null) {
            
    httpObject2.open("GET""dalyviai.php"true);
            
    httpObject2.send(null); 
            
    httpObject2.onreadystatechange setOutput;
        }
    }
    setInterval(doWork100);
     
    var 
    httpObject2 null;
     
    //-->
    </script> 
    <div class="leftside">
    <center>Pamokoje dalyvauja:<hr/>
    <div id='online'>
    </div></center>
    </div>
    <div id="page2">
    <div id="pageinto1">
    <script language="javascript" type="text/javascript">
    // Get the HTTP Object
    function gethttpObject(){
       if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
       else if (window.XMLHttpRequest) return new XMLHttpRequest();
       else {
          alert("Your browser does not support AJAX.");
          return null;
       }
    }  
    function setOutput(){
        if(httpObject.readyState == 4){
            document.getElementById('zinutes').innerHTML = httpObject.responseText;
        }
     
    }
     
    // Implement business logic    
    function Work(){    
        httpObject = gethttpObject();
        if (httpObject != null) {
            httpObject.open("GET", "zinutes.php", true);
            httpObject.send(null); 
            httpObject.onreadystatechange = setOutput;
        }
    }
    setInterval(Work, 1000);
     
    var httpObject = null;
    </script>
    <center>Pamokos pokalbis<hr/></center>
    <div id="zinutes">
    </div>
    </div>
    <div id="pageinto2">
    asd

    </div>
    </div> 
    So, the problem is that first ajax stopped working when I added second one.

    Where is the problem?? maybe I can put the httml.object's together??

    Thanks.
    Last edited by auriaks; 03-12-2010 at 08:59 PM.

  • #2
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts
    if you need more info - ask me...

  • #3
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Exclamation

    Maybe the main problem is that I use
    PHP Code:
    httpObject 
    and
    PHP Code:
    httpObject2 
    ???


  •  

    Posting Permissions

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