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

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 :: ERROR in ./node_modules/pretty-format/node_modules/ansi-regex/index.js Module build failed: Error: ENOENT: no such file or directory 
Javascript :: react native bottom sheet example 
Javascript :: pass data from parent to child component angular 8 
Javascript :: how to get the index of an object inside of a map js 
Javascript :: var = " "; 
Javascript :: radio button not checked when clicked react 
Javascript :: multi level route static file not found issue in express 
Javascript :: node_modules edux-sagaesindex.js 
Javascript :: javascript nested arrays stackoverflow 
Javascript :: clear input field javascript 
Javascript :: javascript capitalize every word in a string 
Javascript :: how to use bootstrap in reactjs 
Javascript :: Could not parse as expression: "1, "desc" DataTable 
Javascript :: Perform native operation by javascript in Android 
Javascript :: tokenize javascript 
Javascript :: js deconstruct rename 
Javascript :: utility javascript function list 
Javascript :: curl --post with api 
Javascript :: javascript random letters and numbers 
Javascript :: This shorthand syntax is also known as the concise method syntax. It’s valid to have spaces in the property name. 
Javascript :: MongoDB Express Find All In Database 
Javascript :: Underscore _.create() Function 
Javascript :: calculate percentage in javascript 
Javascript :: Both This Have The Same Value 
Javascript :: Creatable Multiselect 
Javascript :: Another _.extend Example 
Javascript :: convert js to tsx 
Javascript :: make navigation open when items are active 
Javascript :: javascript convert color string to rgb 
Javascript :: make react navigation to always re render 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =