chaya chaya - 7 months ago 258
PHP Question

How to post the parameter in ajax call of jquery datatable

As of now I am passing parameter along with URL in ajax call of data table, But I want to pass it as POST method, please anyone one help me regarding parameter passing in post method,here my trial code:

var $table=$('#example').dataTable(
"processing": true,
"serverSide": true,
"bDestroy": true,
"bJQueryUI": true,
"ajax": 'getResult.php?formName=afscpMcn&action=search&mcn_no='+mcnNum+'&cust_nm='+cust_num+'&emp_id='+emp+''
});

Answer

Just pass it like a normal jQuery ajax. Example:

var $table = $('#example').dataTable( 
    "processing": true,
    "serverSide": true,
    "bDestroy": true,
    "bJQueryUI": true,
    "ajax": {
        'type': 'POST',
        'url': 'getResult.php',
        'data': {
           formName: 'afscpMcn',
           action: 'search',
           // etc..
        },
    }
});

In PHP (just the straightforward approach):

getResult.php

$form_name = $_POST['formName'];
// the rest blah blah..
Comments