正如在這裏建議的:https://gist.github.com/HenrikJoreteg/2502497,我正在嘗試將onprogress功能添加到我的jQuery.ajax()
文件上傳中。上傳工作正常,進行中的事件正在發射,但並非如我所料 - 而是在某個時間間隔內重複發射,而上傳完成後它只發射一次。有沒有辦法指定進行中刷新的頻率?或者,我是否想做一些無法完成的事情?這是我的代碼:使用xhrFields可以將進度功能添加到jQuery.ajax()中嗎?
$.ajax(
{
async: true,
contentType: file.type,
data: file,
dataType: 'xml',
processData: false,
success: function(xml)
{
// Do stuff with the returned xml
},
type: 'post',
url: '/fileuploader/' + file.name,
xhrFields:
{
onprogress: function(progress)
{
var percentage = Math.floor((progress.total/progress.totalSize) * 100);
console.log('progress', percentage);
if (percentage === 100)
{
console.log('DONE!');
}
}
}
});
我正在嘗試使用與您相同的JavaScript文件?在服務器端,我使用PHP。你可以給一些服務器端代碼的例子,如何解決該文件?它會幫助我很多。 $ _POST ['文件']不適合我。 – Anam 2013-09-15 04:23:10