Ajax中的未定义索引

I'm new to ajax,I get some error when using it to do a table.This table having search, sort and paging function.

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');
              }   
            });
        }

bellow are my function.php code

<?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;
}


}
?>

after using this code,my search function cannot work.And I get a notice

Notice: Undefined index: current in C:\xxx\xxx\xxxx\function.php on line 92

You haven't verified $params['current']is defined. In this line, you are checking if $params['current'] is set:

if (isset($params['current'])) {
  $page  = $params['current'];
} else {
  $page=1;
};

But what happens if $params['current'] is not set? In line 92 you use $params['current'] always, whether it is defined or not, so you will get the Undefined index error when $params['current'] isn't defined. You have to check before you use this index.

Appears current is not being passed as a parameter in your ajax request.

you could handle this exception by a short hand if statement and set default if it is not present. like:

    $json_data = array(
        "current"       => isset($params['current'])?intval($params['current']):1;, 
        "rowCount"      => 10,          
        "total"         => intval($qtot->num_rows),
        "rows"          => $data   // total data array
    );

PHP 7 introduced the null coalesce operator which simplifies this statement even further if the first parameter is not empty it will use that else the second paramter will be used as the default value. Like this:

$json_data = array(
    "current"       => intval($params['current']) ?? 1
    "rowCount"      => 10,          
    "total"         => intval($qtot->num_rows),
    "rows"          => $data   // total data array
);

This is a back-end solution to handle if current is not set. I would also check your ajax data being prepared to see why it hasn't been included in the request

Since you gave me the code in line 92,

This might help..

You already did a conditional statement

if (isset($params['current'])) { $page  = $params['current']; } else { $page=1; }; 

So you should again use that in your other codes $

json_data = array(
        "current"       => $page,
        "rowCount"      => 10,          
        "total"         => intval($qtot->num_rows),
        "rows"          => $data   // total data array
 );