how to make one your own promise version Ajax



how to make one your own promise version Ajax

XMLHttpRequest

 download

how to make one your own promise version Ajax_Promise

upload

how to make one your own promise version Ajax_Promise_02

"use strict";

/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-05-18
* @modified
*
* @description promise ajax
* @augments
* @example
* @link
*
*/

const log = console.log;

const url = `https://cdn.xgqfrms.xyz/json/cat.json`;

const callback = () => {
log(`callback`)
}

const onLoad = () => {
log(`onload`)
}


const ajax = new XMLHttpRequest();
ajax.open("HEAD", url);
ajax.callback = callback;
ajax.filepath = url;
ajax.onload = onLoad;
ajax.send();



AbstractFactory & Ajax

Promise



Fetch API

jQuery 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)
},
})
})
}