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, 2020 in PHP by kartik
• 37,490 points
5,217 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, 2020 by Niroj
• 82,680 points

Related Questions In PHP

0 votes
1 answer

How can I use jquery $.ajax to call a PHP function?

Hello @kartik, Use $.ajax to call a server context (or ...READ MORE

answered Aug 27, 2020 in PHP by Niroj
• 82,680 points
1,815 views
0 votes
1 answer

How to get the list of specific files in a directory using php?

Hello @kartik, You'll be wanting to use glob() Example: $files = ...READ MORE

answered Nov 6, 2020 in PHP by Niroj
• 82,680 points
79 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, 2020 in PHP by Niroj
• 82,680 points
203 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, 2020 in PHP by Niroj
• 82,680 points
3,274 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, 2020 in Laravel by Niroj
• 82,680 points
1,792 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, 2020 in PHP by Niroj
• 82,680 points
411 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, 2020 in PHP by Niroj
• 82,680 points
169 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, 2020 in PHP by Niroj
• 82,680 points
395 views
0 votes
1 answer

How to get a list of user accounts using the command line in MySQL?

Hello @kartik, Use this query: SELECT User FROM mysql.user; Which ...READ MORE

answered Aug 17, 2020 in PHP by Niroj
• 82,680 points
131 views
0 votes
1 answer

How to resolve the problem of losing a session after a redirect in PHP?

Hello @kartik, Carry out these usual checks: Make sure session_start(); is ...READ MORE

answered Aug 24, 2020 in PHP by Niroj
• 82,680 points
5,064 views