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 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2008
    Location
    Western Belgium
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Problem with two calls

    Hello,

    I have a problem to run function call after another. I hope someone knows the reason

    Code:
    var Pyynto; 
    
    function KasitteleSessiot(koodi,parametri,funktio) 
    { 
        alustaPyynto(); // Not include - copy of "standard"
        Pyynto.onreadystatechange = funktio; 	
        Pyynto.open("POST", koodi, true); 
        Pyynto.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
        Pyynto.send(parametri); 
    }
    
    function TarkistaVirhe() 
    { 
        if(Pyynto.readyState == 4) { 
            if(Pyynto.status == 200) { 
    		alert(Pyynto.responseText);
            } else { 
                alert("Error occurred!"); 
            } 
        } 
    }
    This function is called from link as

    Code:
    function tyhjenna() {	
    
    	alert('Testi1c');	
    KasitteleSessiot('ajax/poistasessiot.php','posx=1&posy=1&paikka=1',TarkistaVirhe);	
    	alert('Testi2c');
      KasitteleSessiot('ajax/talletasessioon.php','kayta=k',TarkistaVirhe);		
    }

    First KasitteleSessiot-call works ok. Second call fails where status <> 200.
    If one of these are alone, there is no problem or if I change order and call last first, then the latter fails. Everytimes I can see both alerts. Any idea?

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You are using global variables, when you call the second one, you override the first one.

    You should look at using a JS Library that is Object Oriented to make the Ajax calls, that way, you will not have the problem.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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