0

This is my first time to use a jSon script and I am not familiar how to fix this, I think my problem is somewhere near the line where I put the <---"POSSIBLE ERROR SOMEWHERE HERE" because the alert is not displaying when it is inside that line.

<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>

This part is not working whenever I place the alert inside this codes it doesn't appear anymore.

$.getJSON( sSource, aoData, function (json) {
          fnCallback(json);
} ); 

Here is the result that is not appearing in the table.

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
            )

Controller

    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;

}
Vince Osana
  • 416
  • 1
  • 5
  • 22
  • Try moving that code block ($.getJSON...) outside of the entire code and try it on its own to see if alert works. if it does, your problem is within the dataTable code.. – Subliminal Hash Mar 31 '16 at 08:03
  • Yes, I already did that, still not working. But the result that are trying to fetch is there when I check it using firebug or Inspect element on chrome. its just not displaying on the table. – Vince Osana Mar 31 '16 at 08:30
  • Ok i guess its because you have to bind your table also in where you call the alert.. so re-structure your code and do as in my answer.. – Subliminal Hash Mar 31 '16 at 09:10

1 Answers1

0

getJSON has not returned the results (async) yet, when you try to bind.

try:

$.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);
        } ); 
Community
  • 1
  • 1
Subliminal Hash
  • 13,614
  • 20
  • 73
  • 104
  • Nothing good happen sir, more errors occur after I paste this code. – Vince Osana Mar 31 '16 at 09:59
  • ok going back to your original script, did you try taking out the double quotes from your sAjaxSource string? E.g. try echo your site_url + "/welcome/get_gen048" – Subliminal Hash Mar 31 '16 at 10:57
  • I tried it sir, it shows the patch to my controller, can you also check my codes on my controller. anyway im using codeigniter as my framework – Vince Osana Mar 31 '16 at 11:14