정렬 기능을 넣기 위해 아작스를 사용하려 합니다...
기본에 아작스를 하나 사용한 것은 분명히 잘 됐는데 이번에 사용하는 것은 안되네요...
이상한 것은 그냥 location.href로 url주소에 변수를 넣어 보냈을 경우 컨트롤러와 지정된 view화면에서 데이터를
제대로 출력합니다 그런데 ajax로 보냈을 경우에는 아무런 반응이 없더군요...
컨트롤러에 변수가 제대로 갔는지 확인하고 싶지만 제가 알고 있는 방법으로는 알 수 있는 방법이 없어서 조언을 구합니다
view(전송화면)
//location.href="/c_note/note/sort/"+sort_test;
$.ajax({
type : "POST",
url : "/c_note/note/sort",
data : {"sort_type" : sort_test},
dataType : "json",
success : function(data){
var sort_list = "";
var rgst = "";
$.each(data,function(i, v){
sort_list += v.QUES_SJ;
});
$("#box").html(sort_list);
}
});
컨트롤러
//$sort_type = urldecode($this->uri->segment(4,0));
$sort_type = $this->input->post("sort_type", true);
$note_id = $this->session->userdata('select_note_id');
$mber_id = $this->session->userdata('sess_user_id');
$cul = '';
$type = '';
$order = '';
if($sort_type == 'a'){
$cul = 'SLTN_REQUST_TP';
$type = 'Y';
}else if($sort_type == 'b'){
$cul = 'QUES_TP';
$type = 'P';
}else if($sort_type == 'c'){
$cul = 'QUES_TP';
$type = 'Q';
}else if($sort_type == 'd'){
$order = 'RGST_DT';
}else if($sort_type == 'e'){
$order = 'QUES_SJ';
}else if($sort_type == 'f'){
$order = 'RGST_ID';
}else if($sort_type == 'g'){
$order = 'DFFLY';
}
$data['q_sort'] = $this->note_model->sort_ques($cul, $type, $order, $mber_id, $note_id);
$data['sort_count'] = $this->note_model->sort_count($cul, $type, $order, $mber_id, $note_id);
$this->load->view('v_note/sort_list', $data);
view(출력화면)
[
<?php
if($q_sort != null){
for($i = 0; $i < $sort_count-1; $i++) {
?>
{
"num" : "<?=$q_sort[$i]->num?>",
"QUES_SJ" : "<?=$q_sort[$i]->QUES_SJ?>",
"RGST_ID" : "<?=$q_sort[$i]->RGST_ID?>",
"QUES_TP" : "<?=$q_sort[$i]->QUES_TP?>",
"RGST_DT" : "<?=$q_sort[$i]->RGST_DT?>",
"OTHBC_YN" : "<?=$q_sort[$i]->OTHBC_YN?>",
"QUES_ID" : "<?=$q_sort[$i]->QUES_ID?>",
"DFFLY" : "<?=$q_sort[$i]->DFFLY?>"
},
<?php
}
?>
{
"num" : "<?=$q_sort[$i]->num?>",
"QUES_SJ" : "<?=$q_sort[$i]->QUES_SJ?>",
"RGST_ID" : "<?=$q_sort[$i]->RGST_ID?>",
"QUES_TP" : "<?=$q_sort[$i]->QUES_TP?>",
"RGST_DT" : "<?=$q_sort[$i]->RGST_DT?>",
"OTHBC_YN" : "<?=$q_sort[$i]->OTHBC_YN?>",
"QUES_ID" : "<?=$q_sort[$i]->QUES_ID?>",
"DFFLY" : "<?=$q_sort[$i]->DFFLY?>"
}
<?php
}
?>
]
중간에 걸려있는 주석은 location.href 성공용입니다.. 분명 location은 출력용 view화면에
[{"변수명" : "변수값"}] <-- 이런 형태로 출력이 됐고, {}뒤에는 콤마가 제대로 붙었습니다.
마지막 {}에는 콤마는 붙지 않았고요.
혹시 아작스는 한 페이지에 하나만 사용이 가능한건가요? 현재 사용하는 아작스 말고도 다른 아작스가 있기는한데..
url이나 시작하는 위치가 다르기에 전혀 상관없을 것 같은데 해답이 나오지 않다보니 그런 생각밖에 들지 않네요
ajax 요청, 응답, 헤더 등등 볼 수 있습니다.
아래 이미지는 포럼에서 지금처럼 댓글 달때의 응답내용입니다.