AJAX传输
例:const xhr = new XMLHttpRequest();
// 此方法因为状态改变被调用多次,实测执行三次(1->2->4)
xhr.onreadystatechange = () => {
if (xhr.readystate === 4 && xhr.status === 200) {
console.log(‘upload success’);
} else {
console.log(‘upload fail);
}
};
xhr.open(‘PUT’, ’网址’);
xhr.setRequestHeader(‘content-type’, ‘application/octet-stream’);
xhr.send(图片文件file);
原文地址:https://www.cnblogs.com/dlm17/p/12345389.html
时间: 2024-11-03 03:19:07