Loop php with javascript cannot get the right order of result -
for(var i=0; i<participantnum; i++){ studentid = $('#txtid'+(i+1)).val(); alert(studentid); //my php function call it's work request(php,paramiter,cb) request("http://localhost/lastorientation/2_registervalidate.php","studentid="+studentid,validateid); }
i value each textbox loop , call php script validate student id
but result come out randomly it's not arrange order increment loop
,by way result come out. know because ajax request can advise
me how result order in way loop does.
thank in advance
sorry language.
it looks request
method doing ajax request serve request, if yes ajax requests asynchronous in nature means cannot predict when callback executed or request completed soon. depends on network speed server speed on serving request.
a possible solution queue requests like
function x(i, limit){ if(i >= limit){ return; } studentid = $('#txtid'+(i+1)).val(); alert(studentid); //my php function call it's work request(php,paramiter,cb) request("http://localhost/lastorientation/2_registervalidate.php","studentid="+studentid,validateid).complete(function(){ x(i + 1, participantnum) }); } x(0, participantnum); function request(){ return $.ajax(...) }
Comments
Post a Comment