Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

wait for ajax to finish

function functABC() {
  return new Promise(function(resolve, reject) {
    $.ajax({
      url: 'myPage.php',
      data: {id: id},
      success: function(data) {
        resolve(data) // Resolve promise and go to then()
      },
      error: function(err) {
        reject(err) // Reject the promise and go to catch()
      }
    });
  });
}

functABC().then(function(data) {
  // Run this when your request was successful
  console.log(data)
}).catch(function(err) {
  // Run this when promise was rejected via reject()
  console.log(err)
})
Comment

Ajax wait until success

$(".my_link").click(
    function(){
    $.ajax({
        url: $(this).attr('href'),
        type: 'GET',
        async: false,
        cache: false,
        timeout: 30000,
        fail: function(){
            return true;
        },
        done: function(msg){ 
            if (parseFloat(msg)){
                return false;
            } else {
                return true;
            }
        }
    });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: getelementsbyclassname remove class 
Javascript :: moment check greater than current time 
Javascript :: how to handle navigation between multiple stack react native 
Javascript :: how to trap js errors window.onerror 
Javascript :: how to convert entered number into currency in words in javascript 
Javascript :: add javascript keyup on input 
Javascript :: js document.addEventListner 
Javascript :: react replace all line breaks with br 
Javascript :: javascript base 10 to base 2 
Javascript :: delete all the rows of table javascript 
Javascript :: redux devtools extention in redux toolkit 
Javascript :: js export multiple functions 
Javascript :: js string does not contain 
Javascript :: promise in forloop 
Javascript :: download json file from s3 
Javascript :: two sum javascript 
Javascript :: javascript get value 
Javascript :: javascript pluck 
Javascript :: get value of choice dropdown in js 
Javascript :: difference between two dates in js 
Javascript :: what are native node modules 
Javascript :: javascript trigger change event 
Javascript :: node fs full path 
Javascript :: js enum 
Javascript :: angular wait all subscriptions 
Javascript :: vue prop string or number 
Javascript :: parent of heap node 
Javascript :: assign class to element javascript 
Javascript :: update chart js with new data 
Javascript :: createelement with id javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =