自动填充功能不适用于Web,但适用于localhost

时间:2017-06-16 07:31:42

标签: javascript php ajax pdo

我有一个使用php进行查询和ajax的自动完成功能,它的工作来自localhost但是当我上传到网络时,它不会工作,这是我的代码。谢谢

<script type="text/javascript">
$(function() {
  
  //autocomplete
  $(".auto").autocomplete({
    source: "search.php",
    minLength: 1
  });       

});
$(function() {
  
  //autocomplete
  $(".auto1").autocomplete({
    source: "search1.php",
    minLength: 1
  });       

});
$(function() {
  
  //autocomplete
  $(".auto2").autocomplete({
    source: "search2.php",
    minLength: 1
  });       

});
</script>

这是我在数据库中的查询

<?php
define('DB_SERVER', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'jobs');


if (isset($_GET['term'])){
    $return_arr = array();

    try {
        $conn = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_NAME, DB_USER, DB_PASSWORD);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        $stmt = $conn->prepare('SELECT employee_name FROM employer WHERE employee_name LIKE :term');
        $stmt->execute(array('term' => '%'.$_GET['term'].'%'));
        
        while($row = $stmt->fetch()) {
            $return_arr[] =  $row['employee_name'];
        }

    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }


    /* Toss back results as json encoded array. */
    echo json_encode($return_arr);
}


?>

感谢您的帮助

0 个答案:

没有答案