Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js promis with ajax

function doTheThing() {
  return new Promise((resolve, reject) => {
    $.ajax({
      url: window.location.href,
      type: 'POST',
      data: {
        key: 'value',
      },
      success: function (data) {
        resolve(data)
      },
      error: function (error) {
        reject(error)
      },
    })
  })
}
Comment

js promis with ajax

doTheThing()
  .then((data) => {
    console.log(data)
    doSomethingElse()
  })
  .catch((error) => {
    console.log(error)
  })
Comment

javascript promise with ajax

function doTheThing() {
  $.ajax({
    url: window.location.href,
    type: 'POST',
    data: {
      key: 'value',
    },
    success: function (data) {
      console.log(data)
    },
    error: function (error) {
      console.log(error)
    },
  })
}
Comment

javascript promise with ajax

doTheThing()
doSomethingElse()
Comment

PREVIOUS NEXT
Code Example
Javascript :: lodash deep clone object 
Javascript :: jquery disable keypress 
Javascript :: how select just before element in jquery 
Javascript :: javascript select all elements 
Javascript :: how to return 5 records instead of 10 records in datatable in laravel 
Javascript :: how to delete a folder in node js 
Javascript :: js remove query param from url 
Javascript :: get 5 months after date in javascript 
Javascript :: how to make slide js in owl carousel auto 
Javascript :: `object` ("[object Object]") cannot be serialized as JSON. Please only return JSON serializable data types 
Javascript :: export variables react 
Javascript :: elasticsearch field not exists 
Javascript :: jquery this 
Javascript :: nested array of object shows as object in console log output js 
Javascript :: js keydown only once 
Javascript :: javascript skip default parameter 
Javascript :: jquery event element is visible 
Javascript :: foreach loop in jquery 
Javascript :: js domtokenlist to array 
Javascript :: create textbox using javascript 
Javascript :: click outside box jquery 
Javascript :: EVERY METHOD 
Javascript :: window vue remove event listener 
Javascript :: jquery datatable iterate all rows 
Javascript :: vue.js function to always uppercase when the client input lowercase 
Javascript :: datatable cdn 
Javascript :: jquery toggle input checkbox 
Javascript :: js dynamicly add script 
Javascript :: react, scroll element into view 
Javascript :: how to delete a variable in js 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =