我試圖做一個Live搜索的展現企業的所有者用戶名,這裏的所有時間是我的代碼:AJAX搜索說「不建議」
PHP文件「f_searchBoForAd.php」
include('functions_cp/f_connection.php');
sqlconnection();
$getName_sql = 'SELECT * FROM businessowner
WHERE businessOwnerUserName LIKE "%' . $searchq .'%"';
$getName = mysql_query($getName_sql) or die (mysql_error());
$a=mysql_fetch_array($getName);
//get the q parameter from URL
$q=$_POST["q"];
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
{
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
if ($hint=="")
{
$hint=$a[$i];
}
else
{
$hint=$hint." , ".$a[$i];
}
}
}
}
// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
JavaScript文件,ajax_framework.js
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","f_searchBoForAd.php?q="+str,true);
xmlhttp.send();
}
我的HTML表單的結果說「不建議」所有的時間,問題出在哪裏?
$ searchq從哪裏來? – BNL 2012-02-03 17:50:02