컨트롤러
public function _remap($method)
{
$rgParams['class']='Json';
$this->output->set_header('Content-Type: application/json; charset=utf-8');
if(method_exists($this, $method))
{
$this->{"{$method}"}();
}
}
public function historyMenuList(){
$this->load->library('form_validation');
$rgParams['menu_idx'] = $this->input->POST('menu_idx', TRUE);
$result = $this->admin_service->historyMenuList($rgParams);
echo json_encode($result);
}
=======================================================================================
뷰페이지
var url = "/json/historyMenuList";
var param = {
menu_idx : $(this).val()
};
$.ajax({
type:"POST",
url :url,
data:param, // data를 json 형식으로 파싱하여 전달,
dataType : "json",//받을 데이터방식
success:function(args){
console.log(args);
},
error:function(e){
}
});
이렇게 보내는데 컨트롤러에 로그를 찍어보면 나오는데..
왜 뷰페이지에는 응답이 없을까요?ㅠㅠ
http://주소//json/historyMenuList를 직접 실행해보면 원하는값을 제대로 echo하는데, js로 호출해보면 아무것도 없다는건가요?
404인건가요? 500인건가요?
안녕하세요 404도 아니고 500도 아닙니다.
컨트롤러에서 디비까지 들어가고 그정보를
$result = $this->admin_service->historyMenuList($rgParams); echo json_encode($result);
이렇게 해서 다시 요청에 대한 응답을 주는데요.
디비까지는 들어가는거 확인되는데 페이지에서 응답이 아예 들어오지않습니다.
console로 직은거는 확인용으로 해놓은겁니다.
왜 안되는지 미쳐버리겠네요ㅜㅜ도와주세요.
http://주소//json/historyMenuList 이렇게 치면 정상적으로 데이터 가져옵니다
text로 하니 데이터를 가져오네요.
근데 ajax 에러를 찍어보니 에러가 아래와 같이 로그가찍히네요
구글에쳐봐도 어떻게 해결해야하는지..잘모르겠네요ㅜㅜ
에러로그는 아래와같습니다.
Uncaught SyntaxError: Unexpected token in JSON at position 0
[{"no":"4","menu_idx":"8","history_year":"1972","reg_date":"2018-04-10 15:30:34","udp_date":"2018-05-15 12:48:20"},{"no":"8","menu_idx":"8","history_year":"1971","reg_date":"2018-04-10 15:30:34","udp_date":"2018-05-15 12:45:28"},{"no":"9","menu_idx":"8","history_year":"1970","reg_date":"2018-04-10 15:30:34","udp_date":"2018-05-17 22:33:13"}]
이렇게 정상적으로 데이터는 가져오는데 이걸 왜 페이지에서 응답으로 못가져오는지 휴..미치겠네요
컨트롤러단에 var_dump로 하니 아래와 같이 나옵니다.
Array
(
[0] => Array
(
[no] => 4
[menu_idx] => 8
[history_year] => 1972
[reg_date] => 2018-04-10 15:30:34
[udp_date] => 2018-05-15 12:48:20
)
[1] => Array
(
[no] => 8
[menu_idx] => 8
[history_year] => 1971
[reg_date] => 2018-04-10 15:30:34
[udp_date] => 2018-05-15 12:45:28
)
[2] => Array
(
[no] => 9
[menu_idx] => 8
[history_year] => 1970
[reg_date] => 2018-04-10 15:30:34
[udp_date] => 2018-05-17 22:33:13
)
)
아예 들어오지 않습니다.
ajax쪽에
success:function(args){
console.log(args);
, error:function(request,status,error){
console.log("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
}
이렇게 했는데 error쪽으로만 빠집니다.
success:function(args){console.log(args);},ajax 요청이 성공하면 여기 부분을 실행하는데 현재는 PHP에서 보내온 값을 개발자 도구의 콘솔에서만 볼 수 있는 문법만 사용하셨습니다. 별도로 DOM을 조작하셔야 될 것 같습니다.