I am using jQuery fileupload plugin and I want to do some custom jQuery stuff once fileupload is done
我使用的是jQuery fileupload插件,一旦文件上传完成,我想做一些自定义jQuery内容。
from here https://github.com/blueimp/jQuery-File-Upload/wiki/Options
从这里https://github.com/blueimp/jQuery-File-Upload/wiki/Options
Now it says this
现在说这
Callback for successful upload requests.
$('#fileupload')
.bind('fileuploaddone', function (e, data) {/* ... */})
Now I have defined this custom function for testing in my own js file
现在我已经定义了这个自定义函数,用于在我自己的js文件中进行测试
$('#fileupload').bind('fileuploaddone', function (e, data) {/* ... */
alert('Hello');
})
But it's not working.
但这不是工作。
But if I edit the main file in here
但是如果我在这里编辑主文件
// Callback for successful uploads:
done: function (e, data) {
Then it works.
它的工作原理。
2 个解决方案
#1
4
Looking at the library code, seems all events are renamed removing 'fileupload' ... so 'fileuploaddone' becomes just 'done'. It is valid for all other callbacks. look at this section:
查看库代码,似乎所有事件都被重命名为删除“fileupload”…所以“fileuploaddone”就变成了“done”。它对所有其他回调都有效。看看这一节:
// Other callbacks:
// Callback for the submit event of each file upload:
// submit: function (e, data) {}, // .bind('fileuploadsubmit', func);
// Callback for the start of each file upload request:
// send: function (e, data) {}, // .bind('fileuploadsend', func);
// Callback for successful uploads:
// done: function (e, data) {}, // .bind('fileuploaddone', func);
// Callback for failed (abort or error) uploads:
// fail: function (e, data) {}, // .bind('fileuploadfail', func);
// Callback for completed (success, abort or error) requests:
// always: function (e, data) {}, // .bind('fileuploadalways', func);
// Callback for upload progress events:
// progress: function (e, data) {}, // .bind('fileuploadprogress', func);
// Callback for global upload progress events:
// progressall: function (e, data) {}, // .bind('fileuploadprogressall', func);
// Callback for uploads start, equivalent to the global ajaxStart event:
// start: function (e) {}, // .bind('fileuploadstart', func);
// Callback for uploads stop, equivalent to the global ajaxStop event:
// stop: function (e) {}, // .bind('fileuploadstop', func);
// Callback for change events of the fileInput(s):
// change: function (e, data) {}, // .bind('fileuploadchange', func);
// Callback for paste events to the pasteZone(s):
// paste: function (e, data) {}, // .bind('fileuploadpaste', func);
// Callback for drop events of the dropZone(s):
// drop: function (e, data) {}, // .bind('fileuploaddrop', func);
// Callback for dragover events of the dropZone(s):
// dragover: function (e) {}, // .bind('fileuploaddragover', func);
If you have some doubts about what's happening, just look at the code inside. This library is not compressed so it is easy to see. for example
如果您对正在发生的事情有疑问,请查看内部的代码。这个库没有被压缩,所以很容易看到。例如
// start: function (e) {}, // .bind('fileuploadstart', func);
start
callback is implemented. fileuploadstart
is not.
开始实现回调。fileuploadstart不是。
#2
8
Check if the server-side uploading script returns a JSON reply - in my case it didn't work when the reply was empty, but file was uploaded successfully.
检查服务器端上传脚本是否返回JSON回复——在我的例子中,当回复为空时,它不能工作,但是文件被成功上传。
So, below is working for me with jQuery 1.9.1 and the newest version of the "jQuery File Upload Plugin" - 5.21.3
下面是jQuery 1.9.1和最新版本的jQuery文件上传插件5.21.3
$("#fileupload").bind("fileuploaddone", function (e, data) {
console.log("fileuploaddone event fired");
});
#1
4
Looking at the library code, seems all events are renamed removing 'fileupload' ... so 'fileuploaddone' becomes just 'done'. It is valid for all other callbacks. look at this section:
查看库代码,似乎所有事件都被重命名为删除“fileupload”…所以“fileuploaddone”就变成了“done”。它对所有其他回调都有效。看看这一节:
// Other callbacks:
// Callback for the submit event of each file upload:
// submit: function (e, data) {}, // .bind('fileuploadsubmit', func);
// Callback for the start of each file upload request:
// send: function (e, data) {}, // .bind('fileuploadsend', func);
// Callback for successful uploads:
// done: function (e, data) {}, // .bind('fileuploaddone', func);
// Callback for failed (abort or error) uploads:
// fail: function (e, data) {}, // .bind('fileuploadfail', func);
// Callback for completed (success, abort or error) requests:
// always: function (e, data) {}, // .bind('fileuploadalways', func);
// Callback for upload progress events:
// progress: function (e, data) {}, // .bind('fileuploadprogress', func);
// Callback for global upload progress events:
// progressall: function (e, data) {}, // .bind('fileuploadprogressall', func);
// Callback for uploads start, equivalent to the global ajaxStart event:
// start: function (e) {}, // .bind('fileuploadstart', func);
// Callback for uploads stop, equivalent to the global ajaxStop event:
// stop: function (e) {}, // .bind('fileuploadstop', func);
// Callback for change events of the fileInput(s):
// change: function (e, data) {}, // .bind('fileuploadchange', func);
// Callback for paste events to the pasteZone(s):
// paste: function (e, data) {}, // .bind('fileuploadpaste', func);
// Callback for drop events of the dropZone(s):
// drop: function (e, data) {}, // .bind('fileuploaddrop', func);
// Callback for dragover events of the dropZone(s):
// dragover: function (e) {}, // .bind('fileuploaddragover', func);
If you have some doubts about what's happening, just look at the code inside. This library is not compressed so it is easy to see. for example
如果您对正在发生的事情有疑问,请查看内部的代码。这个库没有被压缩,所以很容易看到。例如
// start: function (e) {}, // .bind('fileuploadstart', func);
start
callback is implemented. fileuploadstart
is not.
开始实现回调。fileuploadstart不是。
#2
8
Check if the server-side uploading script returns a JSON reply - in my case it didn't work when the reply was empty, but file was uploaded successfully.
检查服务器端上传脚本是否返回JSON回复——在我的例子中,当回复为空时,它不能工作,但是文件被成功上传。
So, below is working for me with jQuery 1.9.1 and the newest version of the "jQuery File Upload Plugin" - 5.21.3
下面是jQuery 1.9.1和最新版本的jQuery文件上传插件5.21.3
$("#fileupload").bind("fileuploaddone", function (e, data) {
console.log("fileuploaddone event fired");
});