After the JSON response is executed, the previous JSON response is executed after :
function nextItem(i) {
var currentitem = items[i];
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost/items.php",
data: "{'itemname' : currentitem}",
dataType: "json",
complete: function() {
if (i<numitems) {
i++;
nextItem(i);
}
},
error: function(request, status, errorThrown) {
alert(status);
}
});
}
source
share