How to post the parameter in ajax call of jquery datatable?

0 votes

I am passing parameter along with URL in ajax call of data table.

But I want to pass it as POST method,  so anyone can help me regarding parameter passing in post method?

Here's my  code:

// Sending through GET
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+''
});
Jun 16 in PHP by kartik
• 20,980 points
263 views

1 answer to this question.

0 votes

Hello @kartik,

Just pass it like a normal jQuery ajax in POST fashion.

The structure should look like this:

ajax: { type: 'POST', url: <path>, data: { your desired data } }

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 access the POST indices as usual (just the straightforward approach):

getResult.php

$form_name = $_POST['formName'];
// the rest of your values ...

Hope this is helpfull!!

Thank You!!

answered Jun 16 by Niroj
• 44,800 points

Related Questions In PHP

0 votes
1 answer

How to override trait function and call it from the overridden function?

Hello, If the class implements the method directly, ...READ MORE

answered Apr 7 in PHP by Niroj
• 44,800 points
144 views
0 votes
1 answer

How to get the client IP address in PHP ?

Hello, Here is a code sample of a good ...READ MORE

answered Apr 8 in PHP by Niroj
• 44,800 points
794 views
0 votes
1 answer

How can I get ID of the last updated row in MySQL?

Hello @kartik, Suppose, item_id is an integer identity column in items table ...READ MORE

answered Apr 9 in PHP by Niroj
• 44,800 points
214 views
0 votes
1 answer

How to get the current plugin directory in WordPress?

Hello @kartik, This will actually get the result ...READ MORE

answered May 8 in PHP by Niroj
• 44,800 points
104 views
0 votes
1 answer

Why it is necessary to refresh CSRF token per form request?

Hello, Generating a new CSRF token for each ...READ MORE

answered Mar 19 in Laravel by Niroj
• 44,800 points
499 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27 in PHP by Niroj
• 44,800 points
69 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27 in PHP by Niroj
• 44,800 points
57 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27 in PHP by Niroj
• 44,800 points
60 views
0 votes
1 answer

How to merge two arrays while keeping keys instead of reindexing in php?

Hello, Considering that you have $replaced = array('1' => ...READ MORE

answered Apr 1 in PHP by Niroj
• 44,800 points
63 views
0 votes
1 answer

How can I handle the warning of file_get_contents() function in PHP?

Hello @kartik, This is fairly simple: if (!$data = ...READ MORE

answered Apr 7 in PHP by Niroj
• 44,800 points
272 views