<form action="url" enctype="multipart/form-data" id="myform" method="post">
<input accept="image/*" id="addfile" type="file" />
</form>
$("#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("上传失败!请重试!");
}