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
    Regular Coder
    Join Date
    May 2009
    Posts
    143
    Thanks
    14
    Thanked 1 Time in 1 Post

    Timer help - racing

    hey,

    I posted something in Ajax section but find that it should be here.

    I have 3 select boxes,
    when you choose an option from the first, the second select gets populated based on the first choosen option. Same goes for the third select.

    when they submit the data, I want to put back the values in those select based on the URL string. All goes well except for a racing condition.

    I tried using a mutex and / or setTimout without success. it always results in an infinite loop.

    Using alerts to debug tells me that mutex is true then becomes false when Ajax call has ended.

    I know this is some epik javascript needs but I need to know the inner working of this language
    thanks

    js1.js :
    Code:
    var mutex = false;
    
    function doSomethingAjax()
    {
            mutex = true; //while im here, mutex is active
    	xmlhttp = GetXmlHttpObject();
    	if (xmlhttp==null)
    	{
    	  alert ("Votre navigateur ne supporte pas le XMLHTTP!");
    	  return;
    	}
    	url = './consulter_ajax.php?id_domaine=' + id_domaine + '&sid=' + Math.random();
    	xmlhttp.onreadystatechange=doPopulerListeProgrammes;
    	xmlhttp.open("GET",url,true);
    	xmlhttp.send(null);
    }
    
    function doPopulerListeProgrammes(){
    	if (xmlhttp.readyState==4)
    	{
    		document.getElementById("slcProgrammeIE").innerHTML=xmlhttp.responseText;
    		clearCours();
    		toggleElementDisable(document.getElementById("niveauADesactiver"), true); //désactive les niveaux
    		mutex = false; //release the mutex
    	}
    }
    And here comes js2.js

    Code:
    function getValeursDepartURL(){
    	//domaine
    	if(document.getElementById('slcDomaine')){
    		var domaine = document.getElementById('slcDomaine');
    		var id_domaine = getValeurURL('slcDomaine');
    		if(id_domaine){
    			selectIndexParValeur(domaine, id_domaine);
    			populerListeProgrammes(id_domaine);
    		}
    	}
    	
            while(mutex){} //INFINITE LOOP
            //alert(mutex); //= true
            //alert(mutex); //= false...
    
    	//Programme
    	if(document.getElementById('slcProgramme')){
    		var programme = document.getElementById('slcProgramme');
    		var id_programme = getValeurURL('slcProgramme');
    		if(id_programme){
    			selectIndexParValeur(programme, id_programme);
    			populerListeCours();
    		}
    	}
    Last edited by Jahren; 06-18-2009 at 10:01 PM.

  • #2
    Regular Coder
    Join Date
    May 2009
    Posts
    143
    Thanks
    14
    Thanked 1 Time in 1 Post
    So I found out it's completely impossible.
    I had to integrate a state manager checking whether the user or my code fired the ajax calls. but it's fixed anyhow


  •  

    Posting Permissions

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