Nico
Nico

Reputation: 105

Remotipart getting ajax response

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.

Upvotes: 1

Views: 1386

Answers (1)

chuck w
chuck w

Reputation: 1761

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.

Upvotes: 5

Related Questions