Is it possible to make this loop wait until the AJAX call has finished before moving onto the next iteration?
for(curr;curr < total;curr++) {
$this.val('Uploading '+(curr+1)+' out of '+total);
var tmpStr = JSON.stringify(o[curr]).replace("&", "and");
tmp[0] = JSON.parse(tmpStr);
$.ajax({
type: 'POST',
url: 'http://example.com/api/post',
data: "data="+JSON.stringify(tmp),
success: function(msg) {
var d = JSON.parse(msg);
if (d.success) {
//localStorage.removeItem("data");
}
else
{
alert("Data failed to upload, please try again");
}
},
error: function(msg) {
alert("Data failed to upload, please try again");
$this.val('Upload to CMS');
}
});
}