I want to execute Ajax in a loop to fetch data one by one. I did something like this in my javascript function.
var resultType = $("input[name='resultType']:checked").val();
var finalResult = "";
var loadingMessage = "<img src=\"./results/loader.gif\" alt=\"Loading...\"/><br/>This may take several minutes...";
var htmlMessage=loadingMessage;
$("#result").html(htmlMessage);
for(var i=1;i<5;i++){
$.ajax({
type: "GET",
url: "results/result_html.php?usn="+i+"&resultType="+resultType,
dataType:"JSON",
success:function(result){
finalResult+=result;
result=result+htmlMessage;
$("#info").hide();
$("#result").html(result);
$("#usn").attr("placeholder", "Class USN");
}
});
}
But it is not executing as I expected. If I remove for loop and give value directly then everything is proper. I'm not much familiar with Ajax. Please can anyone help me?