Please help me understand why my ajax code runs only on the first loop. I have an array of JSON. Each JSON needs to be processed to get the response from the server. What happens is that "Processing..." were logged in console number of times as the length of arrayJSON, then the first loop will run ajax. After that I'm getting timeout errors. Below is my code. Many thanks!
$.each(arrayJSON, function(i, arrayJSONInstance) {
jsonString = JSON.stringify(arrayJSONInstance);
$.ajax({
url: "php/phpcode.php",
data: {
data: jsonString
},
dataType: "json",
type: "POST",
timeout: 0,
beforeSend: function (response) {
console.log("Processing...");
},
success: function (response) {
console.log(response);
console.log("Success!");
},
error: function(response) {
console.log("ERROR:\n");
console.log(response);
}
});
});