Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

jquery wait for function to finish

   // *use promisses*// 
//example
function function(info) {
    return new Promise(function(resolve, reject) {
        $.ajax({
            method: "POST",
            url: "file.php",
            data: {
                "info": info,
            },
            success: function(data) {
                resolve(data) // Resolve promise and go to then()
            },
            error: function(err) {
                reject(err) // Reject the promise and go to catch()
            }
        });
    });
}
 //in the call of function
function("data").then((data)=>{
	console.log(data);
	});
 
PREVIOUS NEXT
Tagged: #jquery #wait #function #finish
ADD COMMENT
Topic
Name
8+2 =