📅  最后修改于: 2022-03-11 15:02:48.033000             🧑  作者: Mango
$('#input-file').change(function() {
var url = '/back-end-url';
var form_data = new FormData();
var xhr = new XMLHttpRequest();
$.each(this.files, function (key, value) {
form_data.append('file', value)
})
xhr.open('POST', url, true)
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
xhr.send(form_data)
xhr.onreadystatechange(function() {
if(xhr.readyState == XMLHttpRequest.DONE) {
var res = JSON.parse(xhr.responseText)
}
})
})