| 제목 | jqeury 댓글 삭제 관련 질문입니다. | ||
|---|---|---|---|
| 글쓴이 | 이손 | 작성시각 | 2015/11/12 16:45:54 |
|
|
|||
|
삭제 버튼을 누르는 순간 $('#row_num_' + xhr.responseText).remove(); 부분 에러 메시지가 뜨네요.. 이리 저리 바꿔보다 결국 안돼서 도움 요청합니다..ㅠ 추가질문.. ajax_comment_delete 컨트롤러에서 댓글 삭제 성공시 왜 echo $board_id; 를 하는지 모르겠습니다.
<script type="text/javascript">
$(function(){
$("#comment_add").click(function(){
$.ajax({
url: "/bbs/index.php/ajax_board/ajax_comment_add", //요청 보낼 서버의 URL
type: "POST", //전송 타입
data: { //url로 전송할 데이터를 key:value 형태로 선언
"comment_contents": encodeURIComponent($("#input01").val()),
"table": "<?php echo $this->uri->segment(3); ?>",
"board_id": "<?php echo $this->uri->segment(5); ?>"
},
dataType: "html", //응답 결과 형태 (html,xml,script,json,jsonp,text)
complete: function(xhr, textStatus){ //요청이 완료되었을 경우 호출 (XMLHttpRequest 객체 응답 데이터, 성공 여부에 대한 값을 문자열로 받음)
if(textStatus == 'success'){ //성공했을 경우
if(xhr.responseText == 1000){
alert('댓글 내용을 입력하세요.');
}else if(xhr.responseText == 2000){
alert('다시 입력하세요.');
}else if(xhr.responseText == 9000){
alert('로그인 후 사용하실 수 있습니다.');
}else{
$("#comment_area").html(xhr.responseText); //comment_area 엘리먼트의 자식 노드에 xhr.responseText 내용 추가
$("#input01").val(''); //input01의 내용을 공백으로 채움 (전송 후 내용부분 초기화)
}
}
}
});
});
$(document).on('click','.comment_delete', function(e){
e.preventDefault(); //url에 #이 생기는것을 방지
$.ajax({
url: "/bbs/index.php/ajax_board/ajax_comment_delete",
type: "POST",
data: {
"table": "<?php echo $this->uri->segment(3);?>",
"board_id": $(this).attr("data-vals")
},
dataType: "text",
complete: function(xhr, textStatus){
if(textStatus == 'success'){
if(xhr.responseText == 9000){
alert('로그인하여야 합니다.');
}else if(xhr.responseText == 8000){
alert('본인의 댓글만 삭제할 수 있습니다.');
}else if(xhr.responseText == 2000){
alert('다시 삭제하세요.');
}else{
$('#row_num_' + xhr.responseText).remove();
alert('삭제되었습니다.');
}
}
}
});
});
});
</script>
//==============================게시판 댓글 삭제
public function ajax_comment_delete(){
//로그인 되었을 시
if($this->session->userdata('logged_in') == TRUE){
$this->load->model('board_m'); //모델 로드
$table = $this->input->post("table", TRUE);
$board_id = $this->input->post("board_id", TRUE);
//글 작성자가 본인인지 검증
$writer_id = $this->board_m->writer_check($table, $board_id);
if($writer_id->user_id != $this->session->userdata('username')){
//작성자 불일치
echo "8000"; //본인이 작성한 글이 아닙니다.
}else{
$result = $this->board_m->delete($table, $board_id);
if($result){
echo $board_id;
}else{
echo "2000"; //삭제 실패
}
}
}else{
echo "9000"; //로그인 필요 에러
}
}
|
|||
| 다음글 | alert 문의입니다. (2) | ||
| 이전글 | redirect 문제.. (7) | ||
|
변종원(웅파)
/
2015/11/13 08:57:43 /
추천
0
|
|
이손
/
2015/11/16 16:22:00 /
추천
0
오타가 있었네요 처리했습니다. 답변 감사드립니다.
|
292페이지 9번항목에서도 다시 설명하고 있습니다.
어떻게 안되는지 에러메세지를 올려주셔야 합니다. ^^