Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  126] [ 1]  / answers: 1 / hits: 21707  / 11 Years ago, mon, august 19, 2013, 12:00:00

I use jQuery's ajax()to get information. I call the method when the request is successful. Here is the code:



function recursively_ajax(){
console.warn(begin);
$.ajax({
type:GET,
url: ./JvmInfoClass,
success: function(data){
console.warn(get jvm info success);
recursively_ajax();
}
});
}

recursively_ajax();


I make the thread sleep 3 seconds in the back-end. But the console print the message continuously not after 3 seconds. Why is this?


More From » jquery

 Answers
12

You can try this with ajax call async:false



var counter=0;
function recursively_ajax()
{
var pass_data=5;
var chartMenu=['VTR','NC','RC','TOCU','TOCO','TR','COA','MP'];
$.ajax({
type:POST,
async:false, // set async false to wait for previous response
url: url to server,
dataType:json,
data:{dataMenu:pass_data},
success: function(data)
{
counter++;
if(counter < chartMenu.length){
recursively_ajax();
}
}
});
}
recursively_ajax();

[#76279] Saturday, August 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adriannemyiag

Total Points: 504
Total Questions: 105
Total Answers: 99

Location: Ecuador
Member since Thu, Apr 22, 2021
3 Years ago
;