您的位置:首页 > Web前端 > JQuery

jQuery异步上传表单(包含文件)

2015-03-12 00:00 190 查看
摘要: 使用jQuery异步上传文件,支持绑定进度条事件。无刷新,支持微信。

这段代码用得太顺手了,可惜忘了出处(应该是stackoverflow上面)。在此感谢原作者。

var formData = new FormData($('form')[0]);
$.ajax({
url: 'URL',  // Server script to process data
type: 'POST',
xhr: function() {
// Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr()
// Check if upload property exists
if (myXhr.upload) {
// For handling the progress of the upload
myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
}
return myXhr;
},
// Ajax events
beforeSend: function() {},
success: function (data) {},
error: function (err) {},
// Form data
data: formData,
// Options to tell jQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jQuery 异步上传