我想使用Ajax與jQuery數據表組合使用動態表,問題是,sAjaxSource
參數沒有提出發佈請求(我通常使用chromes web工具來檢查頭文件和響應代碼,我期望POST方法和響應)。腳本正在加載,控制檯中也沒有jquery的錯誤。我怎樣才能讓這個Ajax電話發生?AJAX調用似乎永遠不會發生
下面是表的jQuery:
$(document).ready(function(){
$('#datatable-courses').dataTable({
"bJQueryUI": true,
"bAutoWidth": false, // disable auto width calculation
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"bProcessing": true,
"bServerSide": true,
"sServerMethod":"POST",
"sAjaxSource": "admin/courses/ajax_get_courses",
"iDisplayLength": 10,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"aLengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]],
"aaSorting": [[0, 'asc']],
"aaSorting": [], // sorting off initially
"aoColumns": [
{ "bVisible": true, "bSearchable": true, "bSortable": true, "sWidth": "60px" },
{ "bVisible": true, "bSearchable": true, "bSortable": true, "sWidth": "250px" },
{ "bVisible": true, "bSearchable": true, "bSortable": true, "sWidth": "70px" },
{ "bVisible": true, "bSearchable": true, "bSortable": true, "sWidth": "70px",
}
],
"fnServerParams": function (aoData) {
aoData.push({ "name": "my_csrf_name", "value": $.cookie('my_csrf_cookie') });
}
}).fnSetFilteringDelay(700);
下面就一起來看看我的控制器,雖然我懷疑問題就在這裏:
public function ajax_get_courses()
{
if (! $this->input->is_ajax_request() || ! is_server_request_method('POST')) {
return FALSE;
}
$this->load->model('courses_model');
$data = $this->courses_model->ajax_get_courses();
echo $data;
flush();
exit();
}
ADDITIONA信息:
使用jQuery數據表0.7,codeigniter
config var for csrf token設置爲tru即
如果您可以解釋令牌如何修復sAjaxSource的問題將會很有幫助 –