使用拓展运算符拷贝对象,只能拷贝一层,属于浅拷贝
ES6阅读需 1 分钟
function sendAjax(url) {
return new Promise((resolve,reject) => {
// 1. 创建对象
const x = new XMLHttpRequest();
// 2. 初始化
x.open('GET',url);
// 3. 发送
x.send();
// 4. 事件绑定
x.onreadystatechange = function() {
if (x.readyState === 4) {
if (x.status >= 200 && x.status <= 300) {
resolve(x.response);
} else {
reject(x.status);
};
};
};
});
};
async function readAjax() {
let result = await sendAjax('https://api.apiopen.top/getJoke');
console.log(result);
}
readAjax();
trimStart()方法用于清除字符串左侧空白,trimEnd()方法用于清除字符串右侧空白。