jquery ajax promise
function ajax(options) {
return new Promise(function (resolve, reject) {
$.ajax(options).done(resolve).fail(reject);
});
}function doTheThing() {
$.ajax({
url: window.location.href,
type: 'POST',
data: {
key: 'value',
},
success: function (data) {
console.log(data)
},
error: function (error) {
console.log(error)
},
})
} $.ajax({
url: "/someurl",
method: "GET",
data: {
a: "a"
})
.done(function(data) {
console.log('success callback 1', data)
})
.done(function(data) {
console.log('success callback 2', data)
})
.fail(function(xhr) {
console.log('error callback 1', xhr);
})
.fail(function(xhr) {
console.log('error callback 2', xhr);
});
Also in JavaScript:
- how to concatenate strings javascript
- node.js server
- combine values of address line 1 and address line 2 javascript
- javascript disable button
- javascript continue
- javascript slice
- objeto con método javascript
- js remove property from object
- javascript convert date from mm/dd/yyyy to yyyymmdd
- prime numbers javascript
- javascript round up
- how to show multiple image preview in jquery
- navigation.openDrawer is not a function react native
- jquery populate select from json
- vue js Elements in iteration expect to have 'v-bind:key' directives
- ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: [object Object]'. Current value: 'ngIf: true'.
- async map js
- readfilesync
- javascript to get value of dropdown
- state with react functions
- how to use function in javascript
- webpack react proxy not working
- js capitalize first letter of each word
- comments in js