...

View Full Version : Resolved Timer help - racing



Jahren
06-18-2009, 03:39 PM
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 :


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



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();
}
}

Jahren
06-18-2009, 10:01 PM
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 ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum