I have 2 ajax call in 2 difference functions. I want to use .click to call these 2 functions
. The func1 is inserting data in to database, then func2 is to retrieve the data so my question is how to wait until the func1 fully complete then it only execute the func2.
I tried .delay(), it works but i think this is a stupid solution.
$("#updateLocation").click(function(e){
e.preventdefault;
func1();
func2();
});
return false;
});
function func1(){
$.ajax({
url:'',
});
});
function func2(){
$.ajax({
url:'',
});
});
Three ways:
Call func2 on success of func1:
Use
DeferredAPI to call func2 when func1 completes:Make func1 synchronous (not recommended):