Search
 
SCRIPT & CODE EXAMPLE
 

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);
	});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to read a csv file in nodejs 
Javascript :: modulo operator in javascript 
Javascript :: how to convert jsonobject to string in java 
Javascript :: math random js 
Javascript :: javascript array.find 
Javascript :: jquery get all inputs in form 
Javascript :: javascript return object property from array 
Javascript :: change focus to next field jquery after enter 
Javascript :: adding background video angular 6 
Javascript :: get position of element in react 
Javascript :: remove duplicates multidimensional array javascript 
Javascript :: javascript check if object is null or empty 
Javascript :: get match number array javascript 
Javascript :: add array to array js 
Javascript :: disable button js 
Javascript :: express redirect with post data 
Javascript :: create select option using jquery 
Javascript :: how can when click buton scrool to another elemtn 
Javascript :: get current url react router 
Javascript :: cookie options 
Javascript :: falsy values javascript 
Javascript :: debounce javascript 
Javascript :: converting object to an array in javascript 
Javascript :: ReactDOMServer import 
Javascript :: javascript reload page without refresh 
Javascript :: window.location.href url.action parameters 
Javascript :: react testing for links 
Javascript :: import svg as react component 
Javascript :: useref reactjs 
Javascript :: htpp code 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =