0
我正在学习asp.net和jQuery,现在我想在PHP中实现一个简单的自动完成,我能够做这样的事:如何使用asp.net和json实现jquery-ui自动完成?
这里的客户端代码:
<link type="text/css" rel="stylesheet" href="css/jquery-ui-1.8.17.custom.css"/>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.5.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('.auto').autocomplete(
{
source: "search.php",
focus: function(event, ui) {
$(idField).val(ui.item.value);
$(this).val(ui.item.label);
return false;
},
select: function(event, ui) {
//$(this).val(ui.item.label);
$(this).val(ui.item.label);
var a = "#"+$(this).attr('id');
$(a+"hidden").val(ui.item.value);
return false;
}
//minLength: 3
});
});
</script>
这里是我的代码,不会搜索:
<?php
$host = "localhost";
$user = "root";
$password = "";
$db = "isproj2";
// open connection
$connection = mysql_connect($host, $user, $password) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
$text = mysql_real_escape_string($_GET['term']);
$query = "Select SupplierName, SupplierID from tbl_supplier where SupplierName LIKE '%$text%'";
$result = mysql_query($query);
$data = array();
$first = true;
while ($row = mysql_fetch_array($result)) {
$data[] = array('label' => $row['SupplierName'], 'value' => $row['SupplierID']);
}
echo json_encode($data);
?>
我希望发生的是做这样的事情asp.net,在一些文章我读过,我需要使用Web服务。