1

i am using Remotipart to upload files. The Rails-Controller handles the file but i cant figure out how to get the following ajax response. Here is my js code.

$file.children(".description").html(
    '<%= form_for FileObject.new, :url => file_object_index_path , :html => { :multipart => true }, :remote => true do |f| %>' +
    '<div class="field">' +
    '<%= f.label :file %>' +
    '<%= f.file_field :file %>'+
    '</div>' +
    '<input type="hidden" name="directory_object_id" value="' + current_directory.id +'" />' +
    '<div class="actions">' +
            '<%= f.submit %>' +
            '</div>' +
    '<% end %>'
 );
$("form").bind('ajax:success', function(){
   alert("success");
});

Maybe someone has solved this before.

Nico
  • 105
  • 1
  • 9

1 Answers1

5

Instead of binding to ajax:success, try this:

$("form").bind("ajax:complete", function(e, data, status, error){
    if (data.status === 200 || data.status === 201) {
        ...
    }
})

I have had trouble binding ajax support when using remotipart, and have used the above workaround in the past.

chuck w
  • 1,741
  • 2
  • 15
  • 34
  • 1
    It may be that your response is HTML rather than the JS remotipart expected by default. See my response to this similar question about how to fix this more elegantly: http://stackoverflow.com/questions/14508260/parse-error-using-remotipart – Nik Haldimann May 24 '13 at 01:06