ビューコードである:(符号付き)CodeIgniterの+ jQueryのUIのオートコンプリート= 500内部サーバーエラー
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- Load JQuery UI -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$("#input").autocomplete({
source: function(req, add){
$.ajax({
url: '<?php echo base_url(); ?>test/ac2',
dataType: 'json',
type: 'POST',
//data: req,
data: 'input='+req,
success: function(data){
if(data.response =='true'){
add(data.message);
}
}
});
},
minLength: 2,
select: function(event, ui){
$(this).end().val(ui.item.value);
}
});
});
</script>
</head>
<?php
echo form_open();
echo form_input('input', '', 'id="input"');
echo form_close();
?>
</html>
とコントローラコード:
class Test extends CI_Controller {
function index()
{
$this->load->view('vw/test_vw');
}
public function ac2()
{
//$search = $this->input->post('term');
$search = $this->input->post('input');
$data['response'] = 'false';
$this->db->select('*');
$this->db->from('loc_exercise');
$this->db->like('locations', $search);
$locations = $this->db->get()->result();
if (count($locations) > 0) {
$data['message'] = array();
foreach ($locations as $location) {
$data['message'][] = array( 'label' => $location->locations,
'item' => $location->locations,
'value' => $location->locations);
}
$data['response'] = 'true';
}
echo json_encode($data);
}
Iは入力には何も入力しますボックス私は、コンソール上でこれを取得する:
POST http://my.example.com/test/ac2 500 (Internal Server Error)
とCIエラーには(log_thresholdは1、/ logsです何の問題もないように思わログに記録しますchmod 777)。
私はconfig.phpにquery_strings TRUEとallow_get_array TRUEを設定しています。
この問題を解決する方法はありますか?あなたの質問で
あなたはそれを釘付けにしました - CSRFをオフにしたら、オートコンプリートのドロップダウンが正常に機能しました。私はCSRFを使うつもりです...まだCIフォーラムで提供されているソリューションを消化していません:P - とにかくおかげで! – pepe
上記の@coolgeekによって投稿されたブログ記事は素晴らしく、この問題を解決する方法をうまく説明しています – pepe
うれしい – coolgeek