这是我第一次使用jSon脚本而且我不熟悉如何解决这个问题,我认为我的问题是在某处附近我将< ---"可能的错误放在这里&# 34;因为警报在该行内时不会显示。
<script>
$(document).ready( function () {
$('#acctable').dataTable({
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"bFilter": false,
"bProcessing": true,
"bLengthChange": false,
"bServerSide": true,
"sAjaxSource": "<?php echo site_url() ?>/welcome/get_gen048",
"sServerMethod": "GET",
"fnServerData": function (sSource, aoData, fnCallback ) {
aoData.push( { "name": "sfdate" , "value": "<?php echo $_POST["sfdate"] ?>" } );
$.getJSON( sSource, aoData, function (json) {
alert("a")<----------"POSSIBLE ERROR SOMEWHERE HERE"
fnCallback(json);
} );
},
"aoColumns": [
{ "mdata" : "leftAligned" , "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false }
]
});
}
);
</script>
每当我将警报放在此代码中时,此部分就无法正常工作。
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
} );
以下是未出现在表格中的结果。
Array
(
[sEcho] => 1
[iTotalRecords] => 6
[iTotalDisplayRecords] => 6
[aaData] => Array
(
[0] => Array
(
[0] => 000590071555
[1] => JOSEPHINE PADILLA NICOLAS OR LEONCIO SALUNDAY NICOLAS
[2] => 20 G CRUZ ST. ESTEBAN SOUTH DALANDAN
[3] => 07-18-2015
[4] => 0MPJBHANDIG
[5] => VALENZUELA CITY
[6] => 1059
)
[1] => Array
(
[0] => 000870026392
[1] => ISLAS COMMODITY TRADER INC
[2] => 6F DON JACINTO BLDG 141 SALCEDO ST LEGASPI
[3] => 07-18-2015
[4] => 0HMDAVID
[5] => MAKATI
[6] => 2087
)
控制器
function search_gen048() {
//echo 'ehllo';
$data['sfdate']=$this->input->post('sfdate');
//echo '-'. $data['sfDate'] . '-';
$data['main_content'] = 'sgen048';
$this->load->view('includes/template',$data);
}
function get_gen048(){
$this->load->model('navi_model');
$query = $this->navi_model->srch_gen048($_GET);
//echo $query;
}
答案 0 :(得分:0)
当你尝试绑定时,getJSON还没有返回结果(async)。
尝试:
$.getJSON( sSource, aoData, function (json) {
alert("a")<----------"POSSIBLE ERROR SOMEWHERE HERE"
$('#acctable').dataTable({
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"bFilter": false,
"bProcessing": true,
"bLengthChange": false,
"bServerSide": true,
"sAjaxSource": "<?php echo site_url() ?>/welcome/get_gen048",
"sServerMethod": "GET",
"fnServerData": function (sSource, aoData, fnCallback ) {
aoData.push( { "name": "sfdate" , "value": "<?php echo $_POST["sfdate"] ?>" } );
},
"aoColumns": [
{ "mdata" : "leftAligned" , "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false },
{ "sClass": "rightAligned", "bSortable" : true, "bAutoWidth": false }
]
});
fnCallback(json);
} );