Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于XMLHttpRequest相关 #185

Open
ckinmind opened this issue Jun 19, 2019 · 1 comment
Open

关于XMLHttpRequest相关 #185

ckinmind opened this issue Jun 19, 2019 · 1 comment

Comments

@ckinmind
Copy link
Owner

ckinmind commented Jun 19, 2019

XMLHttpRequest上传文件demo例子

const formdata = new FormData()
formdata.append('file', file)
formdata.append('name', filename)
formdata.append('other', 'test')

const xhr = new XMLHttpRequest()
xhr.addEventListener('load', ev => {
    if (ev.target.status === 200) {
        // 成功处理
    }
}, false)

// 上传失败
xhr.addEventListener('error', ev => {
// 失败处理
}, false)

// send
xhr.open('POST', url)
xhr.setRequestHeader('test', '123')
xhr.send(formdata)
@ckinmind
Copy link
Owner Author

XMLHttpRequest.upload相关事件可以获取上传进度

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant