Reputation: 15673
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.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.fileupload-ui.js
Upvotes: 1
Views: 7629
Reputation: 21
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
Upvotes: 2
Reputation: 8275
To summarize the previous comments, 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).
Upvotes: 3