问题描述
我的jQuery文件上传插件有一个奇怪的问题。
如果我使用此sitax:
I have a weird problem with jQuery File Upload plugin.If I use this sitax:
$('fileupload').fileupload({
url: myurl,
add: function(e, data){
console.log("add event");
},
processalways: function(e, data){
console.log("processalways event");
}
});
没有发生processalways事件,但我得到了正确的 data.context 变量(即带有添加文件的进度条的div)。
processalways event don't occur, but I got correct data.context variable (i.e. the div with the progress bar of the added file).
当我使用此sintax时
While when I use this sintax
$('fileupload').fileupload({
url: myurl
}).on('fileuploadadd',function(e, data){
console.log("add event");
}).on('fileuploadprocessalways', function(e, data){
console.log("processalways event");
});
正确发生processalways事件,但我错了 data.context (I想想在这种情况下data.context将始终引用 $('fileupload')元素。
processalways event correctly occur, but I got wrong data.context (I think in this case data.context will always refer to $('fileupload') element.
我需要进程事件和 data.context 变量。我该怎么办?
I need both process event and data.context variable. How can I do?
推荐答案
第一语法
如果你想开始这个过程,你必须在添加功能中调用 data.submit();
。
然后你不能调用 processalways
回调,它应该使用始终
:
Then you can't call a processalways
callback, according to the documentation it's always
which should be used :
$('input').fileupload({
url: "/echo/json",
add: function (e, data) {
console.log("Add callback");
$('#start_upload').click(function(){
data.submit();
});
},
always: function (e, data) {
console.log("Always callback");
}
});
第二语法
我从来没有使用它,但如果它工作,因为 fileuploadd
不存在。所以它是默认的 fileuploadadd
,它可以调用 data.submit()
。
Second syntax
I've never use it, but if it works it's because fileuploadd
doesn't exist. And so it's the default fileuploadadd
which is used, and it may call data.submit()
.
这篇关于为什么jQuery File Upload插件的进程事件不会触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!