I'm attempting to trigger the ajax:success callback for a remote link. I'm on Rails 3.0.8 and jquery-rails 1.0.11. I ran the jquery generator to install the javascripts. Both jquery and jquery_ujs are included in my defaults and I can verify they are being included on the page.
Here's my javascript:
jQuery(function($) {
$("#deactivate")
.bind("ajax:success", function() {
alert("HELLO");
})
.bind("ajax:error", function() {
alert("GOODBYE");
}
);
});
The link:
= link_to 'Deactivate', activate_patient_path(patient), :id => 'deactivate', :class => "button button-red", :remote => true
The activate action:
def activate
patient = Patient.find(params[:id])
patient.do_not_call = !patient.do_not_call
if patient.save
render :nothing => true
else
render :status => 500, :nothing => true
end
end
The ajax call seems to be working fine. The action is triggered and I can see the changes in the database. However, the ajax callbacks are not being triggered. I can't get any of them to work. I can get other events, such as click, to work perfectly.
If I debug rails_ujs in Firebug I see that the following code gets ran from the Rails ajax block:
success: function(data, status, xhr) {
element.trigger('ajax:success', [data, status, xhr]);
}
I'm stumped. Any ideas?
make sure that you are not including jquery.js again after rails.js...I ran into a similar problem where jquery.js was included twice, and rails.js was included in between.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With