我是ajax的新手,甚至没有向别人学习 现在我在使用ajax时遇到传递id的问题 的index.php
<table id="employee_grid" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>N0</th>
<th>TICKET ID </th>
<th>CATEGORY </th>
<th>ORDER TYPE</th>
<th>RECEIVED DATE </th>
<th>AGENT/STAFF NAME </th>
<th>EFORM ID</th>
<th>LATEST ORDER STATUS</th>
<th style="width:170px;">Edit</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$( document ).ready(function() {
$('#employee_grid').DataTable({
"bProcessing": true,
"serverSide": true,
"ajax":{
url :"run.php", // json datasource
type: "post", // type of method , by default would be get
"aoColumnDefs" : [
{
'bSortable' : false,
'aTargets' : [3,4]
}],
"dataSrc": function (jsonData) {
for ( var i=0, len=jsonData.data.length ; i<len ; i++ ) {
jsonData.data[i][1] = jsonData.data[i][1]+jsonData.data[i][2]+jsonData.data[i][3]+jsonData.data[i][4];
jsonData.data[i][8] = '<a href="cus_details.php" class="btn btn-primary btn-xs"> View Details </a> <a href="update_details.php" class="btn btn-primary btn-xs"> Update Status </a>';
}
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>
我知道我应该添加一些东西href =“cus_details.php?XXXXXXX”,但我不知道需要放什么
run.php
<?php
//include connection file
include_once("conn.php");
// initilize all variable
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
//define index of column(sorting)
$columns = array(
0 => 'NO_ID',
1 => 'TICKET_ID',
2 => 'CAT_C_B',
3 => 'ORDER_TYPE',
4 => 'RECEIVED_DATE',
5 => 'AGENT_STAFF_NAME',
6 => 'EFORM_ID',
7 => 'LATEST_ORDER_STATUS'
);
$where = $sqlTot = $sqlRec = "";
// check search value exist(search)
if( !empty($params['search']['value']) )
{
$where .=" WHERE ";
$where .=" ( NO_ID LIKE '".$params['search']['value']."%' ";
$where .=" OR TICKET_ID LIKE '".$params['search']['value']."%' ";
$where .=" OR CAT_C_B LIKE '".$params['search']['value']."%' ";
$where .=" OR ORDER_TYPE LIKE '".$params['search']['value']."%' ";
$where .=" OR RECEIVED_DATE LIKE '".$params['search']['value']."%' ";
$where .=" OR AGENT_STAFF_NAME LIKE '".$params['search']['value']."%' ";
$where .=" OR EFORM_ID LIKE '".$params['search']['value']."%' ";
$where .=" OR LATEST_ORDER_STATUS LIKE '".$params['search']['value']."%' )";
}
// getting total number records without any search
$sql = "SELECT * FROM `cusinfo` ";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '') {
$sqlTot .= $where;
$sqlRec .= $where;
}
$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";
$queryTot = mysqli_query($conn, $sqlTot) or die("database error:". mysqli_error($conn));
$totalRecords = mysqli_num_rows($queryTot);
$queryRecords = mysqli_query($conn, $sqlRec) or die("error to fetch cusinfo data");
//iterate on results row and create new index array of data
while( $row = mysqli_fetch_row($queryRecords) ) {
$data[] = $row;
}
$json_data = array(
"draw" => intval( $params['draw'] ),
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval($totalRecords),
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
?>
答案 0 :(得分:0)
您可以传递参数,如下例所示:
$('#employee_grid').DataTable({
"ajax": {
"url": "run.php",
"data": {
"user_id": 451
}
}
} );
此处&#39; user_id&#39;是假定的参数。
答案 1 :(得分:0)
您可以使用数据参数来添加其他参数。 如需了解更多信息,请查看https://datatables.net/examples/server_side/custom_vars.html
Sheets(shtnme).Columns("A:Z").Clear