i am using datatables with serverSide option, but i want to pass a javascript variable into php variable to use it later on php sql select request. i need sending that var without refreshing the page. Thanks
<script type="text/javascript"> $( document ).ready(function() { $('#employee_grid').DataTable({ "bProcessing": true, "serverSide": true, "bStateSave": true, "searching": true, "aaSorting": [[0,'desc']], "ajax":{ url :"response2.php", //json datasource type: "post", //type of method, by default would be get "aoColumnDefs" : [ { 'bSortable' : true, 'aTargets' : [1,2,3,4,5,6,7,8,9] }], "dataSrc": function (jsonData) { for ( var i=0, len=jsonData.data.length ; i<len ; i++ ) { jsonData.data[i][1] = '<font size="4px">'+jsonData.data[i][2]+'</font>'; <?php $phpvar=jsonData.data[i][2]; $sql="SELECT * FROM clientwhere id='$phpvar'"; ... ?> } return jsonData.data; }, error: function(){ // error handling code // $(".employee-grid-error").html(""); //$("#employee_grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>'); $("#employee_grid_processing").css("display","none"); } } }); }); </script>
$_SESSION
$.ajax
POST (or GET) request, passing in the JavaScript variable as a param, to another page (eg processValue.php ). (POST) Example:
$.ajax({
method: "POST",
url: "processValue.php",
data: { someVariable: someValue }
});
$_SESSION
variable Example:
$_SESSION["javascriptVariableValue"] = $_POST['someVariable'];
$_SESSION
variable will have the value accessible in index.php that you can process later NOTE:
index.php and processValue.php file names are used merely for example purposes...
Never access $_POST directly without sanitizing etc. --- this is shown merely for example purposes and to get you going!
In index.php and processValue.php , make sure you do session_start();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.