Reputation: 73
I'm having issues with jquery live firing on ajax success. Here is my link_to function.
<%= link_to image_tag("cross.png"), patient_recurrence_detail_path(params[:id],f.object.id), :remote => true, :class => 'delete_recurrence_detail', :method => :delete, :confirm=>'Are you sure you?' %>
The method it calls is this
def destroy
@recurrence_detail = RecurrenceDetail.find(params[:id])
@recurrence_detail.destroy
respond_to do |format|
format.html { redirect_to patient_path(params[:patient_id]) }
format.js { render :nothing => true }
end
end
Lastly, I have a jquery live function attached to the link created. (I've used .bind() here to no avail)
$('a[data-method="delete"]').live("ajax:success", function(data, textStatus, jqXHR){
$(this).parents('div.fields').remove();
});
I notice in my network traffic I am receiving a status of OK for the delete before, so I am a bit puzzled as to why the live function is not being called. Note: I've also tried using .bind() as well. I do have the jquery-rails gem.
Update: I've tried using .ajaxSuccess() and updated my gem, but still no success. Do I need to add something to my respond_to for ajax?
Upvotes: 3
Views: 716
Reputation: 71939
Until now, I didn't know that was even possible! Then I learned from the docs that Ajax events are broadcast to all DOM elements.
As per the documentation, you should be binding to ajaxSuccess
, not "ajax:success".
Upvotes: 0
Reputation: 6825
minimalistic answer, i know, but maybe try the more current api.jquery.com/on?
edit: i think the gem just got bumped to jquery 1.7.1 about a month ago...
Upvotes: 1