Php 使用Ajax的Jquery UI自动完成从

Php 使用Ajax的Jquery UI自动完成从,php,ajax,jquery-ui,autocomplete,Php,Ajax,Jquery Ui,Autocomplete,我对使用Ajax的jQueryUI的自动完成插件有问题 它在本地工作,但并不总是在服务器上工作,因为每当我只使用一个字符或根本不使用字符时,控制台会给我“UncaughtTypeError:Cannotreadproperty'split'of null”。它只适用于2个字符。。。真的很奇怪真的 这些是我的档案 ajax.php: <?php require_once 'config.php'; if(!empty($_POST['type'])){ $type = $_POST

我对使用Ajax的jQueryUI的自动完成插件有问题

它在本地工作,但并不总是在服务器上工作,因为每当我只使用一个字符或根本不使用字符时,控制台会给我“UncaughtTypeError:Cannotreadproperty'split'of null”。它只适用于2个字符。。。真的很奇怪真的

这些是我的档案

ajax.php:

 <?php
require_once 'config.php';
if(!empty($_POST['type'])){
    $type = $_POST['type'];
    $name = $_POST['name_startsWith'];
    $query = "SELECT id_pro, name, IFNULL(SUM(qty),0) as qty FROM inventory where ".$type." LIKE '%".$name."%' group by id_pro";
    $result = mysqli_query($con, $query);
    $data = array();
    while ($row = mysqli_fetch_assoc($result)) {
        $name = $row['id_pro'].'|'.$row['name'].'|'.$row['qty'];
        array_push($data, $name);
    }

    echo json_encode($data);exit; }?>
<?php
require_once 'config.php';
if(!empty($_POST['type'])){
    $type = $_POST['type'];
    $name = $_POST['name_startsWith'];
    $query = "SET NAMES utf8";
    $result = mysqli_query($con, $query);
    $query = "SELECT id_pro, name, IFNULL(SUM(qty),0) as qty FROM inventory where ".$type." LIKE '%".$name."%' group by id_pro";

    $result = mysqli_query($con, $query);
    $data = array();
    while ($row = mysqli_fetch_assoc($result)) {
        $name = $row['id_pro'].'|'.$row['name'].'|'.$row['qty'];
        array_push($data, $name);
    }

    echo json_encode($data);exit;
}
?>
despacho.php

   <td><input class="case" type="checkbox"/></td>
    <td><input type="text" data-type="id_pro" name="itemNo[]" id="itemNo_1" class="form-control autocomplete_txt changesNo" autocomplete="off" required></td>
    <td><input type="text" data-type="name" name="itemName[]" id="itemName_1" class="form-control autocomplete_txt changesNo" autocomplete="off" required></td>
    <td><input type="number" name="stock[]" id="stock_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" readonly></td>
    <td><input type="number" min="1" name="quantity[]" id="quantity_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" required></td>

在互联网上搜索了一段时间后,我意识到了这个问题。 我为所有带有重音符号的字段获取空值。解决办法很简单

ajax.php:

 <?php
require_once 'config.php';
if(!empty($_POST['type'])){
    $type = $_POST['type'];
    $name = $_POST['name_startsWith'];
    $query = "SELECT id_pro, name, IFNULL(SUM(qty),0) as qty FROM inventory where ".$type." LIKE '%".$name."%' group by id_pro";
    $result = mysqli_query($con, $query);
    $data = array();
    while ($row = mysqli_fetch_assoc($result)) {
        $name = $row['id_pro'].'|'.$row['name'].'|'.$row['qty'];
        array_push($data, $name);
    }

    echo json_encode($data);exit; }?>
<?php
require_once 'config.php';
if(!empty($_POST['type'])){
    $type = $_POST['type'];
    $name = $_POST['name_startsWith'];
    $query = "SET NAMES utf8";
    $result = mysqli_query($con, $query);
    $query = "SELECT id_pro, name, IFNULL(SUM(qty),0) as qty FROM inventory where ".$type." LIKE '%".$name."%' group by id_pro";

    $result = mysqli_query($con, $query);
    $data = array();
    while ($row = mysqli_fetch_assoc($result)) {
        $name = $row['id_pro'].'|'.$row['name'].'|'.$row['qty'];
        array_push($data, $name);
    }

    echo json_encode($data);exit;
}
?>