自动完成打印头不起作用

时间:2018-07-05 07:56:19

标签: php typehead

typehead建议在真正的主机中不起作用,但是在localhost中它可以正常工作,这是它在真正的主机中不起作用的原因。

这是我的代码

html代码

<form method="POST" action="result.php">
                                    <input type="text" name="city" class="city form-control" Placeholder="Enter Your Area!">
                                    <input type="submit" name="submit" role="button" class="btn btn-primary btn-lg" style="margin-top:-11px;background-color:#FFA500;">    
                                </form>

javascript代码

<script src="js/typeahead.min.js"></script>
<script src="js/bootstrap-3.1.1.min.js"></script>
<script>
        $(document).ready(function() {

            $('input.city').typeahead({
                name: 'city',
                remote: 'search.php?query=%QUERY'

            });

        })
    </script>

PHP代码(search.php)

<?php

//CREDENTIALS FOR DB
define ('DBSERVER', 'localhost');
define ('DBUSER', 'root');
define ('DBPASS','');
define ('DBNAME','hotel');

//LET'S INITIATE CONNECT TO DB
$connection = mysql_connect(DBSERVER, DBUSER, DBPASS) or die("Can't connect to server. Please check credentials and try again");
$result = mysql_select_db(DBNAME) or die("Can't select database. Please check DB name and try again");

//CREATE QUERY TO DB AND PUT RECEIVED DATA INTO ASSOCIATIVE ARRAY
if (isset($_REQUEST['query'])) {
    $query = $_REQUEST['query'];
    $sql = mysql_query ("SELECT locations, loc_id FROM delhi WHERE locations LIKE '%{$query}%' OR loc_id LIKE '%{$query}%'");
    $array = array();
    while ($row = mysql_fetch_array($sql)) {
        $array[] = array (
            'label' => $row['locations'].', '.$row['loc_id'],
            'value' => $row['locations'],
        );
    }
    //RETURN JSON ARRAY
    echo json_encode ($array);
}

?>

这是我的本地主机页面的屏幕截图: enter image description here 您可以在此处查看实时操作-> hostelhome.co

0 个答案:

没有答案