サーバーに ajax リクエストを送信し、json レスポンスを受け取りたいのですが、代わりに html レスポンスを受け取ります。このコードの何が問題なのですか?
//jquery code
$('select[name=category]').click(function(){
$.ajax({
url: "/index.php/category/get_categories",
type: "post",
dataType: "json",
cache: false,
success: function (result) {
var arr = jquery.parseJSON(result);
alert(arr);
}
});
});
//php code
public function get_categories(){
$data = $this->category_model->get_cats_names_ids();
echo json_encode($data);
}
応答は json オブジェクトではなく html ページであり、アラート ボックスは表示されません。dataType:"json" を削除すると、アラート ボックスが表示され、html ページが含まれます。 「var arr = jquery.parseJSON(result);」の後のコード 動作しません。alert("こんにちは"); !