没有显示从php到ajax的任何数据。任何帮助将不胜感激。
HTML:
Search Box:<input type="text" name="search" id="search">
<div id="search1"></div>
AJAX:
$("#search").keyup(function(){
var search=$(this).val();
$.ajax({ //GR ID Generation
method: "GET",
url: "search_rep.php?invo="+search,
})
.done(function( msg ) {
$("#search").html(msg);
$("#search1").val();
});
PHP:
$in = mysql_real_escape_string($_GET['invo']);
$msg = '';
if(strlen($in) > 0 && strlen($in) < 20){
$row = mysql_query("SELECT Bot_Name
FROM bot_info
WHERE Bot_Name
LIKE '%$in%'and Bot_Type='Printed'",$con );
while($result = mysql_fetch_array($row)){
$msg .= $result['Bot_Name'] . "<br />";
}
}
输出应显示为谷歌搜索引擎一旦您键入一个单词自动,所有句子都会显示该单词。
答案 0 :(得分:0)
您似乎没有在PHP中回显任何数据到页面上。考虑尝试
{{1}}
您可能还想看看使用MySQLi而不是PHP中即将推出的MySQL。
如果这不起作用,可能是您的数据库或代码的其他区域的问题,请告诉我。
答案 1 :(得分:0)
javascript
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "cities.php?invo="+str, true);
xmlhttp.send();
}
}
</script>
HTML
<p><b>Start typing a name in the input field below:</b></p>
<form>
First name: <input type="text" onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
PHP / Ajax - &gt; cities.php
$query=mysql_query("select name from cities", $con);
while($row = mysql_fetch_array($query)){
$a[]=$row['name'];
}
$q = $_REQUEST["invo"];
$hint = "";
if ($q !== "") {
$q = strtolower($q);
$len=strlen($q);
foreach($a as $name) {
if (stristr($q, substr($name, 0, $len))) {
if ($hint === "") {
$hint = $name;
} else {
$hint .= ", $name";
}
}
}
}
echo $hint === "" ? "no suggestion" : $hint;