코드이그나이터에서 ajax 통신할 때
실무에서는 어떻게 쓰시는지 궁금합니다.
저는 이런 방식으로 썼는데,
best practice로 고쳐주신다면.. 어떻게 되는지요
[컨트롤러]
<?php
class Ajax extends CI_Controller{
public function index(){
}
public function getAllCode(){
$returnValue = json_encode('hello');
echo $returnValue;
}
}
?>
[뷰]
$.ajax({
type: "POST",
url: "/index.php/Ajax/getAllCode/",
success: function(result){
console.log(result);
}});
우와, 그렇군요.
이렇게 써도 되나.. 항상 찝찝했는데 속이 후련하네요
감사합니다 ^^
네. 작성하신게 기본적인 사용형태입니다. (restful library를 이용하기도 합니다)
ajax용 컨트롤러를 따로 만들거나 하나의 컨트롤러에서 혼용하거나 합니다.