Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

http://stackoverflow.com/questions/14411656

By: a guest on Jan 19th, 2013  |  syntax: PHP  |  size: 1.21 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. I am not sure if this is the correct way as it post repeatedly but does the work so far.
  2.  
  3. In my JS:
  4.  
  5.         //GET SELECTED POSTS/PAGES FOR DELETION
  6.         $("#delete_selection").click(function(event) {
  7.          
  8.                 /* stop form from submitting normally */
  9.                 event.preventDefault();
  10.  
  11.                 $.each($('input[name="delete_selection[]"]:checked'), function() {     
  12.  
  13.                         $.ajax({
  14.                           type: "POST",
  15.                           url: 'post_delete_selection',
  16.                           data:
  17.                                 { selected: $(this).val() },
  18.                           success: function(data){                             
  19.  
  20.                                 setTimeout(function () {
  21.                                         window.location.href = window.location.href;
  22.                                 }, 1000);
  23.  
  24.                                 $('#ajax_message').show().html('Successfully deleted.');
  25.                           },                     
  26.                         });                            
  27.  
  28.                 });    
  29.         });
  30.  
  31. My Controller:
  32.  
  33.         public function post_delete_selection(){
  34.            
  35.         $selectedIds = $_POST['selected']; //THIS GRABS THE VALUES FROM THE AJAX
  36.         $this->posts_model->delete_post_selection($selectedIds);        
  37.  
  38.     }
  39.  
  40. My Model:
  41.  
  42.         function delete_post_selection($selectedIds) {
  43.  
  44.             $this->db->where_in('post_id', $selectedIds)->delete('posts');
  45.  
  46.                 return true;
  47.         }
  48.  
  49. THE ONLY PROBLEM I HAVE NOW IS THE CONFIRMATION BECAUSE RIGHT NOW IT JUST DELETE THE SELECTED CHECKBOXES. =)
clone this paste RAW Paste Data