Jquery Ajax PHP Mysql自动完成功能不起作用

时间:2013-12-23 08:06:15

标签: php jquery mysql ajax autocomplete

有人可以查看this link,并告诉我为什么自动完成文字框无效?

我所拥有的是在 MySQL datadabase“Brangays中名为157400X_XXXXXX的表格,其中包含:

enter image description here

我将这些文件作为PHP文件以及

1-:Get_Auto1.php

<?php
// Database Connection
include("configPDO.php");
// Query to get the usable suggestions
    $likeString = '%' . $_GET['term'] . '%';
// We Will prepare SQL Query
    $STM = $dbh->prepare("SELECT Barangay FROM Barangays WHERE Barangay LIKE :likeString");
// bind parameters, Named parameters always start with colon(:)
    $STM->bindParam(':likeString', $likeString);
// For Executing prepared statement we will use below function
    $STM->execute();
// we will fetch records like this and use foreach loop to show multiple Results
    $STMrecords = $STM->fetchAll();
// Deifne array for category.
    $Category_array = array();
// Use for each loop to push all results in category array.
foreach($STMrecords as $row)
{
// Store all values in $result variable.
$result = $row[0];
// push all values in category array using array_push function which treats array as a stack, and pushes the passed variables onto the end of array.
array_push($Category_array, $result);   
}
// encode it using json_encode which returns a string containing the JSON representation of value.      
$json = json_encode($Category_array);
// echo it for getting it using Ajax function explained above.
echo $json;          
?>

2- configPDO.php

 <?php
// mysql hostname
$hostname = 'fdb3.xxxxxxx.net';
// mysql username
$username = '15740xx_xxxxxx';
// mysql password
$password = 'xxxxxxx';
// Database Connection using PDO with Try Catch Statements
try {
$dbh = new PDO("mysql:host=$hostname;dbname=1xxxxx_xxxxxx", $username, $password);
    }
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
?>

0 个答案:

没有答案