how to make one your own promise version Ajax
how to make one your own promise version Ajax
XMLHttpRequest
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
download
upload
"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)
},
})
})
}
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/12912857.html
未经授权禁止转载,违者必究!