다음 코드는 test2.php
과 관련되어 있습니다. 내 문제는 메뉴에서 선택한 사용자를 고유 ID와 연결해야하므로 URL은 선택한 사용자의 페이지가됩니다. 문제는 id가 정의되지 않았다는 것입니다.MySQL에서 값을 복구 할 수 없습니다
그리고 이유를 모르겠습니다! 내가 도대체 뭘 잘못하고있는 겁니까?
window.location.href = '/profile.php?id='+pieces[1];
에서 제공되는 URL은 /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