php - Sending POST data through datatables ajax request -


i'm trying make simple ajax call in datatables reliant on post array of ids previous page's form. getting error :

invalid json response

which tells me returned json array empty or , have feeling has post data not being sent php/sql external script on ajax requesting data from.

i'm not sure how test don't know how include $_post data in url external php page outright trigger script.

heres current datatables init , php results page:

<?php include_once('../functions.php'); sec_session_start(); print_r($_post['post_id']); <-- making sure post data made far ?>  <script type="text/javascript">       $(document).ready(function() {     var comptable = $('#comptab').datatable({         "processing": true,         "serverside": true,         "ajax": {             "url": "baddebt_ext_sql.php",             "type": "post",             "datatype": 'json',             "data": {"post_id": $_post['post_id']}         },                                       "columns": [             { "data": "provider_num" },             { "data": "provider_name"},             { "data": "261_total_bed_debts", "sclass": "rightalign" },             { "data": "271_medicare_bad_debts", "sclass": "rightalign" },             { "data": "281_non_medicare_bad_debts", "sclass": "rightalign" },             { "data": "1_cost_to_charge_ratio", "sclass": "rightalign" },             { "data": "291_cost_of_non_mcr_bad_debts", "sclass": "rightalign" }         ],         "scrolly":        "600px",         "scrollcollapse": true,         "paging":         false,         "order": [[ 2, "desc" ]],         "olanguage": { "ssearch": "filter fields by:" },         "dom": '<"clear">lfrtipt',         "tabletools": {               "sswfpath" : "../php/tabletools/swf/copy_csv_xls_pdf.swf" }     }); 

and here sql:

<?php include_once('../link_costreport_2013.php'); if(isset($_post['post_id'])){     $in = $_post['post_id']; <-- post data supposed received } $data = array(); foreach ($in $id){     $query = $link->prepare("select id,provider_num, provider_name, 261_total_bed_debts, 271_medicare_bad_debts, 281_non_medicare_bad_debts, 1_cost_to_charge_ratio, 291_cost_of_non_mcr_bad_debts                 `s10`                             `id` = :id");     $query->bindparam(':id', $id, pdo::param_int);     $query->execute();     $results = $query->fetch(pdo::fetch_assoc);     $results['261_total_bed_debts'] = "\$".number_format($results['261_total_bed_debts']);     $results['271_medicare_bad_debts'] = "\$".number_format($results['271_medicare_bad_debts']);     $results['281_non_medicare_bad_debts'] = "\$".number_format($results['281_non_medicare_bad_debts']);     $results['291_cost_of_non_mcr_bad_debts'] = "\$".number_format($results['291_cost_of_non_mcr_bad_debts']);     $results['provider_name'] = "<a id='".$results['id']."' data-toggle='modal' href='#provmodal' class='push'>".$results['provider_name']."</a>";     $data[] = $results; } echo json_encode($data); 

if knows how can json array script without utilizing previous pages $_post data supposed send, gladly post well.

basically i'm wondering if there steps missing when comes feeding array of ids through datatables ajax query , second page's sql. ( example of post_id array this: array ( [0] => 299 [1] => 1555 [2] => 3539 ))

diagnosing problem pretty easy. right mouse click , "inspect element" choose network tab. toggle transaction in interface. you'll see new network transaction in network tab.

click on new network transaction -- should have address you're defining in ajax call. headers show variables sent via post, response show server returned.

the error indicating response fail if paste payload jslint.com , evaluate it. cause of failure require more details you've provided.

in ajax example use, "data" data that's being sent server. send large amount of data in post, i'd enclose inputs in form tag, $.serialize or $.serializearray on form. can send serialized data on variable via data attribute, posted server. there, deal resulting post variables via php.

please update code use 1.10 api variables. support old ones deprecated in future versions.


Popular posts from this blog