[英]send javascript/json variable to a php sql request
我正在使用带有serverSide选项的数据表,但我想将javascript变量传递到php变量中,以便以后在php sql select请求中使用它。 我需要发送该var而不刷新页面。 谢谢
<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(或GET)请求,将JavaScript变量作为参数传递给另一个页面(例如processValue.php )。 (POST)示例:
$.ajax({
method: "POST",
url: "processValue.php",
data: { someVariable: someValue }
});
$_SESSION
变量中 例:
$_SESSION["javascriptVariableValue"] = $_POST['someVariable'];
$_SESSION
变量将具有index.php中可访问的值,您可以稍后对其进行处理 注意:
index.php和processValue.php文件名仅用于示例目的...
切勿在未经消毒等情况下直接访问$ _POST。---此处显示的内容仅出于示例目的,并且可以助您一臂之力!
在index.php和processValue.php中 ,确保执行session_start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.