我在我的 Codeigniter 应用程序上使用了 jQuery 自动完成功能。但由于源路径已损坏,它无法正常工作。
这是我的代码:
jQuery(document).ready(function(){
$('.zipsearch').autocomplete({
source:'jQueryAutocompleteRelatedFields.php',
minLength:2,
select:function(evt, ui)
{
// when a zipcode is selected, populate related fields in this form
this.form.city.value = ui.item.city;
this.form.state.value = ui.item.state;
}
});
});
当前文件 jQueryAutocompleteRelatedFields.php 位于以下文件路径:
www\CI\application\views\search\jQueryAutocompleteRelatedFields.php
本地主机\CI\index.php\search\searchItem
是我的浏览器路径
我怎样才能给出来源?
SearchITem 是在搜索控制器下的功能,
更新:jQueryAutocompleteRelatedFields.php
<?php
class DB
{
const DATABASE = 'inventory';
const HOST = '127.0.0.1';
const USERNAME = 'root';
const PASSWORD = '';
static private $pdo;
static public function singleton()
{
if (!is_object(self::$pdo))
{
self::$pdo = new PDO('mysql:dbname=' . self::DATABASE . ';host=' . self::HOST,
self::USERNAME,
self::PASSWORD);
}
return self::$pdo;
}
private function __construct()
{
}
public function __clone()
{
throw new Exception('You may not clone the DB instance');
}
}
if (!isset($_REQUEST['term']))
{
die('([])');
}
$st = DB::singleton()
->prepare(
'select product_id, product_code, product_name ' .
'from tbl_product ' .
'where product_id like :product_id ' .
'order by product_id asc ' .
'limit 0,10');
$searchZip = $_REQUEST['term'] . '%';
$st->bindParam(':product_id', $searchZip, PDO::PARAM_STR);
$data = array();
if ($st->execute())
{
while ($row = $st->fetch(PDO::FETCH_OBJ))
{
$data[] = array(
'value' => $row->product_id ,
'city' => $row->product_code ,
'state' => $row->product_name
);
}
}
echo json_encode($data);
flush();