When we added the pagination, we also broke the ability to delete posts that are loaded via AJAX. This is because we are using the bind
event handler to tie the click
event to our links, which only happens on page load. So, we'll need to account for the links loaded via AJAX. Thankfully, we can do that using jQuery's live
event handler.
1. Open
master.js
, and change thedelete
post code to uselive
instead ofbind:
$('.delete').live( 'click', function(event){ event.preventDefault(); var location = $(this).attr('href');
2. If you start deleting a bunch of items in the post list, it currently doesn't change the number of posts tied to a user account using JavaScript. While we are here, let's alter the
success
function so that it also updates the number of posts at the top of our post list:$('.delete').live( 'click', function(event){ event.preventDefault(); var location = $(this).attr('href'); $.ajax({ type: 'DELETE...