Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Active Inactive button in cakephp using ajax

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.35k
    Comment on it

    Suppose we have a table name player and in player table we have field like id , image,player_name, status,  etc. Suppose data inside fields are id=1, name=ram, image=abcd.jpg and status=0, Now we want to change status to 1, and again we have to change the status to 0. So we uses ajax for the process because we save our time .


    <div class="container">
    <div class="col-md-10" style="margin-top:20px;">
    		<div class="heading" style="background:#EAEAEA;height:45px;margin-bottom:15px;padding:4px;">
    			<span style="border:1px solid #EAEAEA;margin-top:8px;"><strong><h3 style="margin:0px;color:grey;float:left;">Players Table</h3><strong></span>
    			<span style="float:right;margin-top:4px;font-size:21px;"><?php echo $this->Html->link('Add Players',array('action'=>'player')); ?></span>
    			<!--<span style="float:right;margin-top:14px;"><?php echo $this->Html->link('Player Gallery',array('action'=>'playergalleryview')); ?></span>-->
    		<table class="table table-striped">
    				<th>Player image</th>
    				<th>Player Name</th>
        <?php $i=1; foreach ($Player as $post){if($post['Player']['category'] == 1) $link = 'img_1.jpg'; else if($post['Player']['category'] == 2) $link = 'img_2.jpg'; else if($post['Player']['category'] == 3) $link = 'img_1.jpg'; else $link = 'img_4.jpg';
    	if($post['Player']['status'] == 1) $abcd = 'img8.jpg';else $abcd='img7.png';
    		echo $i;
    		//echo $post['Player']['id']; ?></td>
    		<td><?php echo $this->Html->image('player/'.$post['Player']['profile_pic'],array('style'=>'width:150px;height:100px;'));?></td>
                <?php echo $this->Html->link($post['Player']['player_name'],
    					array('controller' => 'Admin', 'action' => 'player_view', $post['Player']['id'])); ?>
    		<td> <?php echo $this->Html->image('/img/player/'.$link,array('style'=>'width:30px;height:30px;'));?></td>
                    echo $this->Html->link(
                        'Player gallery',
                        array('action' => 'playerimagegallery', $post['Player']['id'])
    				<?php echo $this->Form->PostLink($post['Player']['status']?'active':'inactive',array($post['Player']['status']));?>
    					<td id="load<?php echo $post['Player']['id'];?>">
    								<i data="<?php echo $post['Player']['id'];?>" id="status_<?php echo $post['Player']['id'];?>"  class="status_checks btn <?php echo ($post['Player']['status'])?'btn-success': 'btn-danger'?>">
    							<?php echo ($post['Player']['status'])? 'Active' : 'Inactive'?><img src="#" style="width:40px;height:30px;display:none;" />
     <?php } ?>


      var status = ($(this).hasClass("btn-success")) ? '0' : '1';
      var msg = (status=='0')? 'Deactivate' : 'Activate';
    	var current_element = $(this);
    	var id= $(current_element).attr('data');
    	url = webURL+"admin/playerstatus";
    	  url: url,
    	  data: {
    	  success: function(data)
    			if(status== 1)
    				$("#status_"+id).html('Active').attr('class','status_checks btn btn-success');
    			}else {
    				$("#status_"+id).html('Inactive').attr('class','status_checks btn btn-danger');


    function playerstatus()

    Hope this will help you..

 0 Comment(s)

Sign In

Sign up using

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: