我是ajax的新手,在使用它執行表時遇到一些錯誤。此表具有搜索,排序和分頁功能。在ajax中未定義的索引
function ajaxAction(action)
{
data = $("#frm_"+action).serializeArray();
$.ajax({
type: "POST",
url: "function.php",
data: data ,
dataType: "json",
success: function(response)
{
$('#'+action+'_model').modal('hide');
$("#employee_grid").bootgrid('reload');
}
});
}
波紋管是使用此代碼後,我的function.php代碼
<?php
include_once("connection.php");
session_start();
$db = new dbObj();
$connString = $db->getConnstring();
$params = $_REQUEST;
$action = isset($params['action']) != '' ? $params['action'] : '';
$empCls = new cusinfo($connString);
switch($action)
{
default:
$empCls->getEmployees($params);
return;
}
class cusinfo
{
protected $conn;
protected $data = array();
function __construct($connString)
{
$this->conn = $connString;
}
public function getEmployees($params)
{
$this->data = $this->getRecords($params);
echo json_encode($this->data);
}
function getRecords($params) {
$rp = isset($params['rowCount']) ? $params['rowCount'] : 10;
if (isset($params['current'])) { $page = $params['current']; } else { $page=1; };
$start_from = ($page-1) * $rp;
$sql = $sqlRec = $sqlTot = $where = '';
if(!empty($params['searchPhrase']))
{
$where .=" WHERE ";
$where .=" (NO_ID LIKE '".$params['searchPhrase']."%' ";
$where .=" OR TICKET_ID LIKE '".$params['searchPhrase']."%' ";
$where .=" OR CAT_C_B LIKE '".$params['searchPhrase']."%' ";
$where .=" OR ORDER_TYPE LIKE '".$params['searchPhrase']."%' ";
$where .=" OR RECEIVED_DATE LIKE '".$params['searchPhrase']."%' ";
$where .=" OR AGENT_STAFF_NAME LIKE '".$params['searchPhrase']."%' ";
$where .=" OR EFORM_ID LIKE '".$params['searchPhrase']."%' ";
$where .=" OR LATEST_ORDER_STATUS LIKE '".$params['searchPhrase']."%')";
}
if(!empty($params['sort']))
{
$where .=" ORDER By ".key($params['sort']) .' '.current($params['sort'])." ";
}
// getting total number records without any search
$tid = $_SESSION['sess_user_id'];
$sql = "SELECT * FROM `cusinfo` where AGENT_CODE_STAFF_ID = '$tid' ";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '')
{
$sqlTot .= $where;
$sqlRec .= $where;
}
if ($rp!=-1)
$sqlRec .= " LIMIT ". $start_from .",".$rp;
$qtot = mysqli_query($this->conn, $sqlTot) or die("error to fetch tot customer data");
$queryRecords = mysqli_query($this->conn, $sqlRec) or die("error to fetch customer data");
while($row = mysqli_fetch_assoc($queryRecords))
{
$data[] = $row;
}
$json_data = array(
"current" => intval($params['current']),
"rowCount" => 10,
"total" => intval($qtot->num_rows),
"rows" => $data // total data array
);
return $json_data;
}
}
?>
,我的搜索功能不能work.And我得到的通知
Notice: Undefined index: current in C:\xxx\xxx\xxxx\function.php on line 92
你可以在代碼中標出92行嗎? –
「current」=> intval($ params ['current']),.這個代碼在 $ json_data = array –
@ C.Norris猜它是在這裏'intval($ params ['current']),' –