JQUERY - how to get updated value after ajax removes data from within it?

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2011-01-17T20:45:52Z Indexed on 2011/01/17 20:53 UTC
Read the original article Hit count: 117

Filed under:
|
|
|

I have a an element with thumbnails. I allow users to sort their display order (which fires off an update to the DB via ajax). I also allow them to delete images (which, after deletion, fires off a request to update the display order for all remaining images).

My problem is with binding or live I think, but I don't know where to apply it.

The array fired off upon delete contains ALL the ids for the images that were there on page load. The issue is that after they delete an image the array STILL contains the original ids (including the one that was deleted) so it is obviously not refreshing the value of the element after ajax has removed things from inside it. I need to tell it to go get the refreshed contents...

From what I have been reading, this is normal but I don't understand how to tie it into my routine. I need to trigger the mass re-ordering after any deletion.

Any ideas gurus?

    $('a.delimg').click(function(){
 var parent = $(this).parent().parent(); 
 var id = $(this).attr('id');
 $.ajax({
    type: "POST",
    url: "../updateImages.php",
    data: "action=delete&id=" + id,
    beforeSend: function() {
  parent.animate({'backgroundColor':'#fb6c6c'},300);

  $.jnotify("<strong>Deleting This Image & Updating The Image Order</strong>", 5000);
  },
    success: function(data) {
  parent.slideUp(300,function() {
   parent.remove();

  $("#images ul").sortable(function() { //NEEDS TO GET THE UPDATED CONTENT
  var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
  $.post("../updateImages.php", order, function(theResponse){
  $.jnotify("<strong>" + theResponse + "</strong>", 2000);
  });
     });
       });

      }
    });
    return false;
    });

Thanks for any help you can be.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX