Badly Need Help Parsing Http variable to server_processing.php
Badly Need Help Parsing Http variable to server_processing.php
rjbelandres
Posts: 6Questions: 0Answers: 0
Hello,
I'm trying to solve my simple problem and I believe someone can point me to the right direction of even help me what's missing? I have exploring datatable.net for a week and i follow every solution made but no luck. I just wanted to parse Http Get variable to server_processing.php. Here's my code, any idea or solution would be a big break for me.
Client Side:
$(function() {
$( "#srchbtn" ).button
({ icons: { primary: "ui-icon-gear" }
}).click(function(){
$("#sPanel").hide();
$('#example').dataTable( {
bProcessing: false,
bServerSide: true,
bJQueryUI: true,
bRetrieve: true,
sPaginationType: 'full_numbers',
sAjaxSource: "serverside/server_processing.php",
fnServerData: function (sSource,aoData,fnCallback ) {
aoData.push( { "name": "mname", "value": "JAMES" } );
$.ajax( {
"dataType": 'json',
"type": 'GET',
"url": 'serverside/server_processing.php',
"data": aoData,
"success": fnCallback
} );
}
});
$("#rPanel").fadeIn('slow');
});
});
<?php echo $sMiddlename; ?>
Server Side script in server_processing to check if parsing:
if (empty($_GET['mname']) && $_GET['mname']=="")
{$sMiddlename = "No middle name";}
else{$sMiddlename = $_GET['mname'];}
Thanks and More Power DataTables.
I'm trying to solve my simple problem and I believe someone can point me to the right direction of even help me what's missing? I have exploring datatable.net for a week and i follow every solution made but no luck. I just wanted to parse Http Get variable to server_processing.php. Here's my code, any idea or solution would be a big break for me.
Client Side:
$(function() {
$( "#srchbtn" ).button
({ icons: { primary: "ui-icon-gear" }
}).click(function(){
$("#sPanel").hide();
$('#example').dataTable( {
bProcessing: false,
bServerSide: true,
bJQueryUI: true,
bRetrieve: true,
sPaginationType: 'full_numbers',
sAjaxSource: "serverside/server_processing.php",
fnServerData: function (sSource,aoData,fnCallback ) {
aoData.push( { "name": "mname", "value": "JAMES" } );
$.ajax( {
"dataType": 'json',
"type": 'GET',
"url": 'serverside/server_processing.php',
"data": aoData,
"success": fnCallback
} );
}
});
$("#rPanel").fadeIn('slow');
});
});
<?php echo $sMiddlename; ?>
Server Side script in server_processing to check if parsing:
if (empty($_GET['mname']) && $_GET['mname']=="")
{$sMiddlename = "No middle name";}
else{$sMiddlename = $_GET['mname'];}
Thanks and More Power DataTables.
This discussion has been closed.
Replies
You have not defined this variable in THIS php document.
when you sent to the server, it opened a different document and defined $sMiddlename
and since you hard coded the value in as "JAMES" I'm not really sure how you're trying to use the variable in this case (you could assign "JAMES" to it above or simply use the literal "JAMES")
[code]
<?php
require 'serverside/server_processing.php';
echo $sMiddlename;
?>
[/code]
in the serverside:
[code]
$sMiddlename="";
if (empty($_GET['mname']) && $_GET['mname']=="")
{$sMiddlename = "No middle name";}
else{$sMiddlename = $_GET['mname'];}
[/code]
Still I can't get to view the value of $_GET['mname']. Please FBAS tell me what am I missing here.
Thanks in advance and more power
the default script returns an JSONified version of this:
[code]
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array() // the db data is attached here in code below this
);
[/code]
(good reference for the server side values is here: http://www.datatables.net/usage/server-side )
You are free to add any values to this object:
[code]
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array(),
"sMiddlename" => $sMiddlename // add this and any other values you wish to the output json.... I do this a bit for debugging. returning the $sQuery or other values of interest
);
[/code]
--------------
now the next question is: how can you retrieve that value on the client side? you can access the JSON returned in fnServerData
[code]
fnServerData: function (sSource,aoData,fnCallback ) {
aoData.push( { "name": "mname", "value": "JAMES" } );
$.ajax( {
"dataType": 'json',
"type": 'GET',
"url": 'serverside/server_processing.php',
"data": aoData,
"success": function (data, textStatus, jqXHR) {
data.sMiddlename; // do something with sMiddleName.. "data" is the JSON data returned. you could access all the other parts of "data" if you wish, as well.
fnCallback(data,textStatus,jqHXR); // call DT's callback function for the normal processing
}
} );
}
[/code]
reference for the "success" (and $.ajax() ) is at http://api.jquery.com/jQuery.ajax/
I have this code that works base on your reply
client:
[code]
$('#example').dataTable( {
bProcessing: false,
bServerSide: true,
bRetrieve:true,
bJQueryUI: true,
sPaginationType: 'full_numbers',
sAjaxSource: "serverside/server_processing.php",
fnServerData: function (sSource,aoData,fnCallback ) {
aoData.push( { "name": "mname", "value": "JAMES" } );
$.ajax( {
"dataType": 'json',
"type": 'GET',
"url": 'serverside/server_processing.php',
"data": aoData,
"success": function (data, textStatus, jqXHR) {
alert(data.sMiddlename);
fnCallback(data,textStatus,jqHXR);
}
} );
}
});
[/code]
server side:
[code]
$sMiddlename="JAMES";
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array(),
"sMiddlename" => $sMiddlename
);
[/code]
But if I do this on the server side the alert is blank
[code]
$sMiddlename="";
if (isset($_REQUEST["mName"])) $sMname = $_REQUEST["mName"];
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array(),
"sMiddlename" => $sMiddlename
);
[/code]
Do I have to check for any initialization on my php.ini or something. Why can't I get to my GET or POST variables return to my client page.
Thanks in advance and more power datatables
[code]
$_REQUEST = array_merge($_GET, $_POST); // the order you put $_GET and $_POST affects which takes precendence. last added array will overwrite previous array values if the keys are the same
[/code]