7

我正在使用 jQuery 文件上传插件,一旦文件上传完成,我想做一些自定义 jQuery 的东西

从这里 https://github.com/blueimp/jQuery-File-Upload/wiki/Options

现在它这么说

Callback for successful upload requests.
$('#fileupload')
       .bind('fileuploaddone', function (e, data) {/* ... */})

现在我已经在我自己的 js 文件中定义了这个用于测试的自定义函数

$('#fileupload').bind('fileuploaddone', function (e, data) {/* ... */
alert('Hello');
})

但它不起作用。

但是如果我在这里编辑主文件

  // Callback for successful uploads:
            done: function (e, data) {

然后它工作。

4

2 回答 2

8

检查服务器端上传脚本是否返回 JSON 回复 - 在我的情况下,当回复为空时它不起作用,但文件已成功上传。

所以,下面是为我工作的 jQuery 1.9.1 和“jQuery 文件上传插件”的最新版本 - 5.21.3

$("#fileupload").bind("fileuploaddone", function (e, data) {
    console.log("fileuploaddone event fired");
});
于 2013-03-14T20:05:20.563 回答
5

查看库代码,似乎所有事件都被重命名为删除'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);

如果您对发生的事情有一些疑问,只需查看里面的代码即可。这个库没有压缩,所以很容易看到。例如

// start: function (e) {}, // .bind('fileuploadstart', func);

start实现回调。fileuploadstart不是。

于 2012-10-15T08:02:43.407 回答