Welcome Guest, Not a member yet? Register   Sign In
CJAX Vote System Problem with multiple clicks
#1

[eluser]bubx[/eluser]
Hi,
I wrote a simple voting system, and I have a problem with multiple clicks. When I click Like ("Mocne"), I can then click on Unlike ("Słabe"), and a lot of times. I would like to be able to click only once, in one or the other. I use CJAX flush method, but something here does not work properly.

Article view:
Code:
<?php
$this->load->helper('phpHelper'); // plMiesiac

  require_once 'ajax.php';

  $ajax = ajax();
  
  $actionsPlus = array (
  $ajax->call('vote/plus/'.$id,'sum'.$id.'p')
  );
  $actionsMinus = array (
  $ajax->call('vote/minus/'.$id,'sum'.$id.'p')
  );
  
  $ajax->click("#plus".$id,$actionsPlus);
  $ajax->click("#minus".$id,$actionsMinus);

?>
<div class="bs-component">
              <div class="panel panel-default">
                <div class="panel-heading">
     <div >  &lt;?php echo '#'.$id; ?&gt;    </div>
     <div >&lt;?php echo 'Autor: '.$autor.' Dodany: ' ?&gt;
     &lt;?php echo date("d ",$date); ?&gt;
     &lt;?php echo plMiesiac(date("F",$date)); ?&gt;
     &lt;?php echo date("Y",$date); ?&gt;
     &lt;?php echo date("H:m",$date); ?&gt;
     </div>
     </div>
                <div class="panel-body">
                  &lt;?php echo $text ?&gt;
                </div>
    <div class="panel-footer">
    <div class="row">
     <div class="col-md-4">
      <a id="plus&lt;?php echo $id; ?&gt;" href="#"><span class="label label-success">Mocne: <span id="plus&lt;?php echo $id; ?&gt;p">&lt;?php echo $voteplus; ?&gt;</span></span></a>
      <a id="minus&lt;?php echo $id; ?&gt;" href="#"><span class="label label-warning">Słabe: <span id="minus&lt;?php echo $id; ?&gt;p">&lt;?php echo $voteminus; ?&gt;</span></span></a>
      <span class="label label-info">Punkty: <span id="sum&lt;?php echo $id; ?&gt;p">&lt;?php echo ($voteplus - $voteminus); ?&gt;</span></span>
      <span id="info&lt;?php echo $id; ?&gt;" class="label label-warning" ><span>
     </div>
     <div class="col-md-4">
      
     </div>
     <div class="col-md-4">
      <span class="label label-primary">Komentarze:</span>
      <span class="label label-primary">0</span>
     </div>
    </div>
    </div>
              </div>
</div>

Controller:
Code:
&lt;?php

class vote extends CI_Controller{

public function __construct() {
        parent:: __construct();

}

function plus($id){
         $this->load->model('Articles');

  require_once(FCPATH.'ajaxfw.php');
  $ajax = ajax();
  
   $ajax->flush('#plus'.$id);
   $ajax->click("#plus".$id,$ajax->call('vote/showInfo/'.$id,'info'.$id));
   $ajax->flush('#minus'.$id);
   $ajax->click("#minus".$id,$ajax->call('vote/showInfo/'.$id,'info'.$id));
  
  
  $query = $this->db->get_where('articles', array('id' => $id));
  foreach($query->result() as $row) {
   $teraz = $row->voteplus;
   $this->db->where('id', $id);
   $this->db->update('articles', array('voteplus' => $teraz+1));
   echo ($teraz+1)-$row->voteminus;
   }
}
function minus($id){
  $this->load->model('Articles');
  require_once(FCPATH.'ajaxfw.php');
  $ajax = ajax();

   $ajax->flush('#minus'.$id);
   $ajax->click("#minus".$id,$ajax->call('vote/showInfo/'.$id,'info'.$id));
   $ajax->flush('#plus'.$id);
   $ajax->click("#plus".$id,$ajax->call('vote/showInfo/'.$id,'info'.$id));
  
  $query = $this->db->get_where('articles', array('id' => $id));
  foreach($query->result() as $row) {
   $teraz = $row->voteminus;
   $this->db->where('id', $id);
   $this->db->update('articles', array('voteminus' => $teraz+1));
   echo $row->voteplus-($teraz+1);
   }
}
function showInfo($ids){
  require_once(FCPATH.'ajaxfw.php');
  $ajax = ajax();
  $ajax->flush('#plus'.$ids);
  $ajax->flush('#minus'.$ids);
  
  $ajax->replace('#info'.$ids,'<span id="info'.$ids.'" class="label label-warning" >Oddałeś już głos na ten wpis<span>');
}


}


Messages In This Thread
CJAX Vote System Problem with multiple clicks - by El Forum - 08-17-2014, 07:01 AM
CJAX Vote System Problem with multiple clicks - by El Forum - 08-17-2014, 08:38 AM
CJAX Vote System Problem with multiple clicks - by El Forum - 08-17-2014, 11:33 AM
CJAX Vote System Problem with multiple clicks - by El Forum - 08-17-2014, 11:54 AM
CJAX Vote System Problem with multiple clicks - by El Forum - 08-17-2014, 12:34 PM
CJAX Vote System Problem with multiple clicks - by El Forum - 08-17-2014, 01:27 PM
CJAX Vote System Problem with multiple clicks - by El Forum - 08-17-2014, 02:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB