Monday, April 30, 2012

Javascript function taking too long to complete?

Below is a snipet of code that I am having trouble with. The purpose is to check duplicate entries in the database and return "h" with a boolean if true or false. For testing purposes I am returning a true boolean for "h" but by the time the alert(duplicate_count); line gets executed the duplicate_count is still 0. Even though the alert for a +1 gets executed.



To me it seems like the function updateUserFields is taking longer to execute so it's taking longer to finish before getting to the alert.



Any ideas or suggestions? Thanks!



var duplicate_count = 0

for (var i = 0; i < skill_id.length; i++) {

function updateUserFields(h) {
if(h) {
duplicate_count++;
alert("count +1");
} else {
alert("none found");
}
}

var g = new cfc_mentoring_find_mentor();
g.setCallbackHandler(updateUserFields);
g.is_relationship_duplicate(resource_id, mentee_id, section_id[i], skill_id[i], active_ind,table);
};

alert(duplicate_count);




No comments:

Post a Comment