Don P
Don P

Reputation: 63768

Rails 4 - ajax:success isn't being triggered

I submit a form via ajax. I can see in the network panel of Chrome that it was succesfful and returned some JSON. However, the "ajax:success" event is never being fired. Why?

// Does not work, despite getting success in the Network Panel.
$('#uploadDataForm').on("ajax:success", function(){
    console.log('file uploaded!');
});

// Works.
$('#uploadDataForm').on("ajax:send", function(){
    console.log('file sent!');
    console.log('yep');
});

Upvotes: 3

Views: 382

Answers (1)

Rhys
Rhys

Reputation: 459

if your using less than 1.7 Try

$("#uploadDataForm").bind("ajax:success", function() {
      console.log('file sent!');
    console.log('yep');
    });

Otherwise check you are getting a 200 response not 304 or something

or try using the global ajax response ajax .ajaxSuccess()

$(document).on("ajax:success", function() {
      console.log('file sent!');
    console.log('yep');
    });

Upvotes: 1

Related Questions