Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Active and inactive users concept using Ajax in Cakephp

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.30k
    Comment on it

    Concept of active,inactive script is mostly used in Online shopping website, Where adminstrator has right to access the database table and can be able to do changes on the table according to his need. For example a site owner wants to hide some of its product and want to access to check the availability of product, and the status of the product which is going to be sold out in few days.Here is simple line of code of Ajax by which the data is passed in the string form and will display the table of active users whose status is 1 and also the inactive users whose status is 0.

    Ajax Code:

    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script type="text/javascript">
    	$(document).ready(function(){
    		function fetchdata(data){
    			$.ajax({
    		       url:"fetch/"+data,
    		       type:"post",
    		       success:function(result){
    		       	// console.log();
    					$('#table').html(result);
    		       },
    		       error:function(XHR, textStatus, errorThrown )
    		       {
    		       	// alert(textStatus);
    		       }
    
    			});
    		}
    		$('#active').click(function(){
    			fetchdata(1);
    		});
    		$('#inactive').click(function(){
    			fetchdata(0);
    		});
    	});
    </script>
    <a href="#" id="active">active user</a>
    <a href="#" id="inactive">inactive user</a>
    <?php //echo $this->Html->link('active',array('onclick'=>'fetchdata();'));?>
    <?php //echo $this->Html->link('in-active',array('onclick'=>'fetchdata();'));?>
    <div id="table"></div>

    Fetch.ctp:

    <?php
    echo "<table>
    	<tr>
    		<th>Name</th>
    		<th>address</th>
    		<th>number</th>
    		<th>email</th>
    		<th>status</th>
    	</tr>";
    	foreach($result as $value)
    	{
    	echo "<tr><td>".$value['User']['name']."</td><td>".$value['User']['address']."</td>
    		<td>".$value['User']['number']."</td><td>".$value['User']['email']."</td><td>".$value['User']['status']."</td>
    		</tr>";
    	}
    
    echo "</table>";
    ?>


    Controller code:

    public function fetch($data=null)
          {
          	$result=$this->User->find('all', array('conditions'=>array('User.status'=>$data)));
         	 $this->set('result',$result);
          }

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: