admin管理员组

文章数量:1390957

I am using blueimp's Jquery file upload plugin. For adding files, there are a host of different callbacks. For example:

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

I would like to bind to a callback that tells me if a file has been deleted successfully, but I have searched the documentation and can't find anything that looks like it does this. Anyone have an idea how I could do this?

Update: I should say that the above code only returns for UPLOADING a file. No event is returned for deleting a file. This is what I want to try and implement into bluimp's source code.

Source code for callbacks is here .fileupload-ui.js

I am using blueimp's Jquery file upload plugin. For adding files, there are a host of different callbacks. For example:

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

I would like to bind to a callback that tells me if a file has been deleted successfully, but I have searched the documentation and can't find anything that looks like it does this. Anyone have an idea how I could do this?

Update: I should say that the above code only returns for UPLOADING a file. No event is returned for deleting a file. This is what I want to try and implement into bluimp's source code.

Source code for callbacks is here https://github./blueimp/jQuery-File-Upload/blob/master/js/jquery.fileupload-ui.js

Share Improve this question edited Jul 22, 2020 at 8:58 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 27, 2012 at 9:46 GWedGWed 15.7k6 gold badges65 silver badges103 bronze badges 8
  • The state of your downloaded file is known on the server. So in your data variable (it is the json response of your server), you can pass any information and for example, if your file has been deleted successfully. – Samuel Caillerie Commented Nov 27, 2012 at 9:54
  • but the problem is that i then need to implement the handler into the file upload source. Not sure how to do that. – GWed Commented Nov 27, 2012 at 9:57
  • It depends on what you have transmitted from the server (in the datavariable : have you debugged it?). But let's say, you have some object like this : data : { kind : "error", message : "Deletion failed" }, in your callback function you will have to test over data.kind : if (data.kind === "error") alert(data.message);. – Samuel Caillerie Commented Nov 27, 2012 at 10:05
  • Im not sure I am following - the problem is that even if I send the data as you have described, there is no callback function to handle it. Maybe my knowledge has some gaps. Would you be able to add some more detail in an answer? - that would be super helpful. – GWed Commented Nov 27, 2012 at 10:16
  • have added the source code which defines the callback functions. If i could change the code in there to respond to a deletion that would work i think – GWed Commented Nov 27, 2012 at 10:22
 |  Show 3 more ments

2 Answers 2

Reset to default 3

To summarize the previous ments, the callback function is the function that will handle the data received from the server via the event fileuploaddone. Thus, you will have such code :

$('#fileupload').bind('fileuploaddone', callbackfunc); 

// Your callback function
function callbackfunc(e, data) { 
    /* your code, like : if (data.kind === "error") alert(data.message); */ 
}

But you can shorten it via an anonymous function :

$('#fileupload').bind('fileuploaddone', function (e, data) {/* your code, like : if (data.kind === "error") alert(data.message); */})

EDIT

For deletion, the callback can be bound with event fileuploaddestroy (see this page : BlueImp options).

If anybody still looking for this, I found solution by changing "removeNode" function declarations in "destroy" function in jquery.fileupload-ui.js file to:

removeNode = function (d) {
    that._transition(data.context).done(function () {
        $(this).remove();
        that._trigger('destroyed', e, d);
    });
};

then just add event for "fileuploaddestroyed" and data will contain server response instead of original form data

本文标签: javascriptReturn success on delete in JQuery FileUploadStack Overflow