Could you set up a test page with this code? It's difficult to tell just by looking at it. Use Firebug to check and make sure whether it's really resending a request or not, or whether it's somewhere in the code that is incorrectly modifying the wrong parts of the DOM from subsequent requests.
On Feb 20, 1:53 am, Jsbeginner <jsbegin...@monarobase.net> wrote: > Hello, > > I've been working on a jquery projet (with the lastest stable version of > jquery) that retrieves information using json from a php script that > requests information from an API. > The script lists all the different extensions with a status colomn that > says what it's doing (waiting, searching or result). > The script gets the list of extensions form an input select drop down > that's generated by PHP (this allows me to manage extensions using a > database). It then launches the search for the selected extension and > when the search is finished it launches the search for all the other > extensions. > > I need one answer per query but it seems that the ajax success function > is launched more than once which is not what I want, also sometimes it > seems to keep some sort of memory of what the answer was last time (if I > add a sleep function to the php script sometimes it gets the first > answer befor the sleep is over) ... > > I've got a php script to check whois servers that replys with either > taken, available or error. > > When the whois servers answer quickly there are no visible problems, but > when they are slow the ajax request seems to be launched a second time > and sometimes a third time when they are very slow. > > So I might see for example : domain.com, status : available, and then 2 > seconds later it will be replaced by domain.com, status : error and > sometimes then replaced by domain.com, status : available. > > In order to test this I replaced ".html(" by ".append(" and I can then > see all the different results... > > Of course I could check that the html id contains the "searching" text > and if not to not change it's value, but I would like to stop it > launching the search more than once ... ! > > Is this a bug or an error in my code ? should I try it with an earlier > version of jquery ? > > Here is my javascript code : > > function CheckWhois() { > $('#domchk').submit(function() { > ls = Array(); > $("#dext>option").each(function(i){ > i = i+1; > ls[i] = $(this).val(); > }); > var ndom = $('#ndom').val(); > var dext = $('#dext').val(); > $("#domresult").html("<table > id=\"domtab\"><tr><th>Sel.</th><th>Domain</th><th>status</th></tr><tr><td > colspan=\"4\">Chose TLD</td></tr><tr class=\"chosen\"><td><input > type=\"checkbox\" name=\"sel\" value=\""+ndom+dext+"\" > /></td><td>"+ndom+dext+"</td><td id=\"chosenstatus\"><img > src=\"images/domload.gif\" alt=\"en cours ...\" /></td></tr><tr><td > colspan=\"4\">Autres Extensions</td></tr></table>"); > for ( var e in ls) { > if (dext != ls[e]) { > $("#domtab").append("<tr class=\""+ls[e]+"\"><td><input > type=\"checkbox\" name=\"sel\" value=\""+ndom+ls[e]+"\" > /></td><td>"+ndom+ls[e]+"</td><td id=\"status"+e+"\"><img > src=\"images/domball.gif\" alt=\"waiting ...\" /></td></tr>"); > } > } > $.ajax({ > url : "scripts/ajaxwhois.php", > type : "POST", > data : "domain="+ndom+"&ext="+dext, > dataType : "json", > error : function (xhr, desc, exception) > {$("#chosenstatus").html("Error"); }, > success : function (data) { > if(data.error) { > extd.html("Erreur"); > } else { > $("#chosenstatus").html(data.status); > for ( var e in ls) { > var extd = $("#status"+e); > if (dext != ls[e]) { > extd.html("<img > src=\"images/domload.gif\" alt=\"searching ...\" />"); > GetWhois(ndom,ls[e],e); > } > } > } > } > }); > > return false; > }); > > } > > function GetWhois(ndom,ls,e){ > $.ajax({ > url : "scripts/ajaxwhois.php", > type : "POST", > data : "domain="+ndom+"&ext="+ls+"&num="+e, > dataType : "json", > error : function (xhr, desc, exception) { > $("#status"+e).html("Error");}, > success : function (data) { > if(data.error) { > $("#status"+e).html("Error"); > } else { > $("#status"+data.num).append(data.status); > } > } > }); > > } > > $(document).ready(function(){ > CheckWhois(); > > }); > > Thankyou !