Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery-file-upload: how to get server response after destroy?

I'm using jquery-file-upload, and tried without success to receive data from the server after the destroy operation is done

I can see with firebug that the server correctly responds with the json data I expected once the destroy operation is completed (I'm using rails as back-end), but on the jquery side I don't succeed to get the response data. I tried different of the callbacks provided by jquery-file-upload without success

Any hint please? :)

For clarification, I am trying to do something like this:

$('#fileupload').bind('fileuploaddestroyed', function(e, data) {
  console.log(data.response.my_value);
});
like image 827
Benj Avatar asked Jun 12 '13 09:06

Benj


1 Answers

Found an alternative, cause there is apparently no way to natively get server response. A solution would be to modify jquery-file-upload internals, but I implemented this like this:

On fileuploaddestroyed I initiate a second Ajax call. It's not ideal cause it trigger a second HTTP request, but it's the easiest fast implementation I thought about

$('#fileupload').bind('fileuploaddestroyed', function() {
  destroyed_photo();
});


function destroyed_photo() {
  $.ajax({
    url: ($('form#fileupload').attr('action') + '/my_method'),
    dataType: "text",
    type: 'GET',
    processData: false,
    contentType: 'application/json',
    success: function(data) {
      console.log(data); }
  });
}
like image 131
Benj Avatar answered Nov 03 '22 20:11

Benj