html:
jquery:
$("#addfile").on('change', function () {
var f = $(this).get(0).files[0];
var form = document.getElementById('myform');
var formData = new FormData(form);
formData.append('Filedata', f);
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.open('POST', form.action);
xhr.send(formData);
});
function uploadComplete(evt)
{
var data=evt.target.responseText
}
function uploadFailed()
{
alert("上传失败!请重试!");
}
The above is the detailed content of Introduction to the method of asynchronously uploading image files in javascript. For more information, please follow other related articles on the PHP Chinese website!