Server Side Question. How do I send POST variables to the Ajax page?

Server Side Question. How do I send POST variables to the Ajax page?

SkyScreamSkyScream Posts: 22Questions: 1Answers: 0
edited January 2015 in Free community support

$(document).ready(function() {
$('#example').dataTable( {
"processing": true,
"serverSide": true,
"ajax": "../server_side/scripts/server_processing.php"
} );
} );

in this code, how would i set it up to pass post variables in?

Answers

  • zepernickzepernick Posts: 32Questions: 7Answers: 0

    This is an example of a extra parameter user_id being passed in. Your ajax property needs to be turned into a object instead of a string and the url moves into the url property.

    $('#example').dataTable( {
      "ajax": {
        "url": "../server_side/scripts/server_processing.php",
        "data": {
            "user_id": 451
        }
      }
    } );
    

    The Docs have more examples

    The ajax object also has a "type":"post" if you want to do a post instead of a get.

  • SkyScreamSkyScream Posts: 22Questions: 1Answers: 0

    ah thank you. I figured that out. Now I have another problem I posted. Do you think you can help me out with it?

    http://datatables.net/forums/discussion/25520/okay-i-m-trying-to-get-this-to-work-server-side-with-what-i-have-help

  • SkyScreamSkyScream Posts: 22Questions: 1Answers: 0
    edited January 2015

    if I use this method :

    "data": {
    "user_id": 451
    }

    will the data on the server side be retrivable by $_POST["user_id"]
    ?

  • SkyScreamSkyScream Posts: 22Questions: 1Answers: 0
    edited January 2015

    I have this:

    $('#example').dataTable( {
           "processing": true,
            "serverSide": true,
            "ajax": {
            "url": "../includes/views/DetailsTableJSON.php", 
            "type": "POST" }
    
        } );
    

    and i have input fields bellow, in the HTML.
    Am I missing something?
    those input fields aren't being passed to the serverside page as POST data.

This discussion has been closed.