ajaxポスト機能を使用してコントローラからデータを返す際に問題が発生しています。ここでは、ユーザーがスタイル番号を入力し、その番号をコントローラに送信します。コントローラは、提出された値を取得し、データベースに問い合わせて結果をコントローラに返すと、コントローラは次にjsonにエンコードする配列を返します。しかし、私は500内部サーバーのエラーを取得し続けますか?ここでCodeigniterでJSONをPOSTすると500エラーが返される
は私のコントローラは、ここでここで
//return schools based on style id
public function search() {
$input = json_decode($this->input->post('obj'));
$style_id = $input['style_id'];
$parent_id = $input['parent_id'];
$data = array();
if ($q = $this->page_model->search_results($style_id, $parent_id)) {
$data = $q;
}
echo json_encode($data);
}
は私のモデルである
//get all entries
function search_results($style_id, $parent_id) {
$options = array(
'Style' => $style_id,
'Parent_ID' => $parent_id
);
$this->db->select('*');
$this->db->from('pages');
$this->db->join('entry', 'pages.Page_ID = entry.Parent_Page_ID', 'inner');
$this->db->where($options);
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q->result();
}
}
である私のJavascriptを
//dress style search
$($searchBtn).click(function(event) {
var style_id,
parent_id,
obj = {};
//get the value of the input fields
searchVal = event.currentTarget.previousSibling.value;
parentID = event.currentTarget.parentElement.childNodes[3].value;
//The object to be passed to the controller
obj = { 'style_id' : searchVal, 'parent_id' : parentID };
//POST the values in json notation, return the search results in json notation
$.post(base_url + 'index.php/page/search',
obj,
function(data) {
console.log(data);
},
'json');
return false;
});
BASE_URL =はhttp:// localhostを:8888/lexsreg
ご連絡先 - 私がコメントした場合私はコントローラからエコーされたjson文字列を取得します。
ありがとうございます!
CIバージョン2.0.3では、csrfトークンの名前がもう一度変更され、このバージョンの名前は "csrf_test_name" – steampowered
はあなたのクレジットを忘れてしまった –