Hi
What I'm trying to do involves going through a series of checkboxes.
For each one of them that it is checked, I have to perform some calculations (using an ajax call). If there is an error, I have to break the loop and return a message.
Every ajax call takes about 0,4 seconds to perform but that shall never be a problem because I can only have a maximum of 4 of them checked at any given time.
But the problem I'm facing is that, the final alert box pops-up before the one inside the error function(). The error function does work but it appears always after the final one.
I was under the impression that by defining the call as asynchronous=false, code execution would wait until the call returned a response. Is that a wrong assumption?
Is there a way to accomplish this?
Thanks in advance
$("input[id*='chk_aut']").each(function() {
if(this.value=="on") {
$.ajax({
type: "GET",
url: "testpage.asp",
cache:"false",
async:"false",
data: "which=checkvalues&value="
+ i_value
+ "&ref="+$("#cb_ref").val()
+ "&nif="+$("#txt_nif").val()
+ "&day="+i_day
+ "&month="+i_month
+ "&hours="+i_hours
+ "&year="+i_year + "&ms="
+ new Date().getTime(),
success: function(msg) {
//do something but continue the loop
},
error: function() {
i_result =false;
alert("An error has occurred");
return false;//break the loop
}
});
}
});
alert(i_result);