Guest User

http://stackoverflow.com/questions/14411656

a guest
Jan 19th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  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. =)
Add Comment
Please, Sign In to add comment