Search code examples
javascriptajaxresponse

AJAX method calls


Hello I have some functions written in a JS file that I need help with, I have three methods structured like so:

writeDetailsToDB(); //writes details to db and returns a status to indicates success
writeOtherDetailsToDB(); //writes details to db and returns a status to indicates success
checkOk(); //checks to see both status were successful

The problem I am having is that the checkOk() is being called before the other two methods can finish executing so it always indicates failure I need to be be able to wait for the other two methods to finish before executing checkOK(). Having looked a AJAX success methods I always find an .ajax() method and URLs and I don't see how they fit my problem.

Please can someone help me!


Solution

  • Use the success handler of each to progress and perform the next method in sequence.

    You can find documentation and examples of how to use the "success" of the call here: http://api.jquery.com/jquery.ajax/

    EDIT: why the anonymous downvote?