delete data using ajax and codegniter : i have problem in deleting data using ajax i tried first to test if i click the button to make alert action so  it not work so please help me 
**this is my controller code** 
  

    public function indexajax()
    	  {
    
    		  $this->load->model("usersmodel");
    		  $data["allu"]=$this->usersmodel->ShowAllUsers("users");
    		  $data['pagetitle']=" -->All Users Using Ajax<--";
    		  $this->load->view("template/admin/header",$data);
    		  $this->load->view("users/allusersusingajax");
    		  $this->load->view("template/admin/footer");
    
    	  }
    	  public function get_all_users()
    	  {
    		 if($this->input->post("action")=='FetchAllUserUingAjax1'){
    
    		 	$this->load->model("usersmodel");
    			 $x=  $data["allu"]=$this->usersmodel->ShowAllUsers("users");
    			 foreach ($x as $a):
    				 echo'<tr>
                <td>'.$a->id.'</td>
                <td>'.$a->username.'</td>
                <td><button class="deletenew" id="'.$a->id.'">delete</button></td>
    
                </tr>';
    			 endforeach;
    
    
    
    		  }
    public function deleteusers()
    
    	{
    
    
    		$id=$this->input->post("id");
    		$this->load->model("usersmodel");
    		$this->usersmodel->deleteusers($id);
    
    
    	}
 **this is my model code for deleting** 

    public function deleteusers($id)
    		{
    			$this->db->where('id',$id);
    			if($this->db->delete("users")){
    				return true;
    			}else{
    				return false;
    			}
    
    
    		}
**/**************this is view page *****/**

    <div class="userdataajax table-responsive">
        <table class=" table table-responsive table-bordered">
            <tr>
                <th>#</th>
                <th>name</th>
                <th>image</th>
                <th> full name</th>
                <th>email</th>
                <th>usertype</th>
                <th>status</th>
                <th>reg date</th>
                <th>reg time</th>
                <th>delete</th>
                <th>edit</th>
                <th>Activate</th>
                <th>disactivate</th>
    
            </tr>
    
    
        </table>
    </div>


    <script>
    
    	$(document).ready(function () {
    		FetchAllUserUingAjax();
    
    		function FetchAllUserUingAjax() {
    
    			$.ajax({
    				url:'<?php echo base_url()?>Users/get_all_users',
    				method:"post",
    
    				success:function (data) {
    					$(".userdataajax table").append(data);
    
    				}
    			})
    
    
    			var action="FetchAllUserUingAjax1";
    			$.ajax({
    				url:"<?php echo base_url()?>Users/get_all_users",
    				method:"post",
                    data:{action:action},
    				success:function (data) {
    					$(".userdataajax table tr").not("table  
                       tr:first").remove();
                             
    					$(".userdataajax table").append(data);
    					Table();
    
    
    				}
    			})
    
    		};
    		$(".deletenew").on("click",function () {
               alert("engex");//this alert not working
              
    			var id=$(this).attr('id');
    			$.ajax({
    
    				url:"<?php echo base_url()?>Users/deleteusers",
    				method:"post",
    				data:{id:id},
    				success:function () {
    					alert("deleted");
    					FetchAllUserUingAjax();
    
    				}
    
    			})
    		})
    
    
    
    	})
    
    
    </script>
 **// but if i remove foreach *(foreach)* from controller  and put it in view page  delete is working  i want to know  what is my problem**

