AJAX传输图片文件

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);

posted @ 2020-02-22 14:52  对·味  阅读(1127)  评论(0编辑  收藏  举报