2016-08-21 2 views
0

내가 여기에 버튼처럼 만들려고 한JQuery와, 아약스 이그나이터

뷰를 사용하여 버튼처럼 만드는 방법. 그리고 매번 나는 내가 foreach() 루프를 사용하고

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#like").click(function() { 
    var id='1069347886434951';//this is not artist who likes 
    var creation_id= 1; 
    $.ajax({ 
    type: "post", 
    url: "<?php echo base_url(); ?>creations/like_creation", 
    data:'id='+id + '&creation_id=' +creation_id,//after its split, the split function gives an array 
    success: function(response){   
     try{ 
     if(response=='true'){ 
      var newValue = parseInt($("#like").text()) + 1;    
      $("#"+voteId+'_result').html(newValue);// adds the value to no of like on the client side 
     }else{ 
      alert('Sorry Unable to update..'); 
     } 
     }catch(e) { 
     alert('Exception while request..'); 
     } 
    }, 
    error: function(){    
     alert('Error while request..'); 
    } 
    }); 
    }); 
    }); 
    </script> 

컨트롤러 컨트롤러는 데이터베이스에 값을 삽입 JQuery와

에 먹이 데이터베이스에서 값을 넣어 어떻게 여기에 1 씩 증가 버튼을 클릭한다. 우편 배달부를 사용하여 값을 입력하면 json upto ajax를 사용하여 true를 반환합니다. 나는 우체부에서 그것을 시도하고있다.

public function like_creation(){ 
    //$artist_id=$this->session->userdata('user_id'); 
    $artist_id=$this->input->post('id'); 

    //bring creation id from the database when fed using foreach loop 
    $creation_id=$this->input->post('creation_id'); 
    //$up_like1 =0; 
    $data1=array(
    'id'=> $this->input->post('id'),//bring it from artist_infors 
    'creation_id'=> $this->input->post('creation_id'), 
    'artist_who_likes'=> $artist_id , 

    ); 

    $query=$this->hbmodel->insert_like($data1);  


    $status= "true"; 

    echo $status; 
} 

모델

public function no_likes($artist_id, $creation_id) 
{ 
    $sql="SELECT count(like_id) as num from likes as l where id='$artist_id' and creation_id= $creation_id"; 
    //artist id has to determine whether it is user himself or the one whom  he/she tries to follow 
    $query=$this->db->query($sql); 
    return $query->result(); 
} 

MySQL의 쿼리

CREATE TABLE IF NOT EXISTS `likes` (
`like_id` int(11) NOT NULL AUTO_INCREMENT, 
`id` varchar(500) COLLATE utf16_bin DEFAULT NULL,//the artist id whose creation is fed 
`creation_id` int(11) DEFAULT NULL, 
`artist_who_likes` varchar(500) COLLATE utf16_bin DEFAULT NULL, 
PRIMARY KEY (`like_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_bin AUTO_INCREMENT=29 ; 
+0

무엇이 문제입니까? – mplungjan

+0

위 코드를 사용하여 버튼처럼 만들 수 없습니다. 무엇이 잘못 되었습니까? –

+0

오류 메시지가 있습니까? 콘솔 메시지? 또한 try catch가하는 일은 무엇입니까? 성공에 예외를 던지는 코드는 없습니다. 카운터를 반환해야합니다. 진위 또는 거짓이 아닙니다. – mplungjan

답변

0

문제는 성공의 명령에 있습니다. 값은 응답에서 왔지만 문자열과 제대로 비교되지 않았습니다.