我有以下代码,这与test2.php
有关。我的问题是,我必须将菜单中选择的用户与其唯一ID关联起来,因此该URL将成为所选用户的页面。问题是,该ID是未定义的。无法从MySQL中恢复值
而我不知道为什么!我究竟做错了什么?是来自
window.location.href = '/profile.php?id='+pieces[1];
网址为/profile.php?id=undefined
$("#course").autocomplete("/test/test2.php", {
selectFirst: false,
formatItem: function(data, i, n, value) {
//make the suggestion look nice
return "<font color='#3399CC'>" + value.split("::")[0] + "</font>";
},
formatResult: function(data,value) {
//only show the suggestions and not the URLs in the list
return value.split("::")[0];
var username = splitItems[0];
var id = splitItems[1];
return username;
}
}).result(function(event, data, formatted) {
//redirect to the URL in the string
var pieces = formatted.split("::");
window.location.href = '/profile.php?id='+pieces[1];
test2.php
<?php
mysql_connect ("****", "****","****") or die (mysql_error());
mysql_select_db ("****");
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select Username, id from **** where Username LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$cname = $rs['Username'];
echo "$cname\n";
}
?>
尝试记录这些碎片,看看它有什么'console.log(件)' – Sedz
它没有什么... – freddy