passing url parameters server-side

passing url parameters server-side

jeffreyjeffrey Posts: 16Questions: 0Answers: 0
edited October 2011 in General
What is the best way to pass url parameters server-side?

[code]
mypage.php?title=Hello&name=Joe
[/code]

I have a lot of parameters so I'd like to be able to use a variable for the name and value... if for example aoData.push is the way to go.

Thanks.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited October 2011
    if you're using recent version (1.8.2+) and are accepting GET querystring params

    [code]$(document).ready(function() {
    $('#example').dataTable( {
    "bServerSide": true,
    "sAjaxSource": mypage.php",
    "fnServerParams": function ( aoData ) {
    aoData.push( { "name": "title", "value": "Hello" } );
    aoData.push( { "name": "name", "value": "Joe" } );
    }
    } );
    } );[/code]

    if you're using older versions (1.8.1-, but this also still works in 1.8.2+ just more code), OR if you need POST querystring, use this

    [code]/* POST data to server */
    $(document).ready(function() {
    $('#example').dataTable( {
    "bServerSide": true,
    "sAjaxSource": "mypage.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    aoData.push( { "name": "title", "value": "Hello" } );
    aoData.push( { "name": "name", "value": "Joe" } );

    $.ajax( {
    "dataType": 'json',
    //"type": "POST", //uncomment this if you don't want to use GET
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    }
    } );
    } );[/code]
This discussion has been closed.