ajax实时建议搜索不起作用
ajax live suggestion search not working
我正试图创建一个实时搜索,但控制台总是给我一个错误,有人能看看我在做什么吗?提前感谢
这是我的html代码:
<li id="ZoekBalk">
<!--De zoekbalk-->
<form action='films.php' method='get'id='zoekform'>
<input id="ZoekBalkSearch" type="search" name="zoekparameter" placeholder="Geef een zoekterm in." onkeyup="ajaxzoeken(this.value)" />
<input id="ZoekButton" type="submit" value="Zoek"/>
</form>
<div id="resultatenPlaatshouder"></div>
</li>
我的javascript函数:
function ajaxzoeken( str ) {
if ( str.length == 0 ) {
document.getElementById("resultatenPlaatshouder").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("resultatenPlaatshouder").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "ajaxzoeken.php?teZoeken = " + str, true);
xmlhttp.send();
}
和我的php代码:
<?php
require 'data.php';
if ( isset( $_GET['teZoeken'] ) ) {
$tezoeken=$_GET['teZoeken'];
//voeg eventuele extra karakters toe aan de zoekquery
$tezoeken = '%'.$tezoeken.'%';
//zoek in de database (gebruik ook bindparams als beveiliging tegen sql injection)
$query = $connection->prepare("SELECT id,filmnaam,posterlink FROM films WHERE filmnaam ILIKE :zoek ORDER BY filmnaam;");
$query->bindParam(':zoek',$tezoeken,PDO::PARAM_STR);
$query->execute();
//geef alle gevonden films terug in een table
echo '<table>'
while ( $row = $query->fetch( PDO::FETCH_BOTH ) ) {
$id = $row[0];
$filmnaam = $row[1];
$poster = $row[2];
echo "<tr><td><a href='moviePage.php?id=$id'><img class='miniposter' src='$poster' alt='De poster van de film'/></a></td><td><a href='moviePage.php?id=$id'><strong>$filmnaam</strong></a></td></tr>";
}
echo '</table>';
}
?>
我找到了它,忘记了;在回声中,该死的错误
相关文章:
- jQuery Datatables:单个列搜索不起作用
- 搜索按钮谷歌地图在我的vf页面上不起作用
- Angular UI Select2指令搜索功能不起作用
- jQuery .focus() 在 Safari(桌面)的搜索字段中不起作用
- 在js中的表中搜索不起作用
- AngularJS搜索没有'不起作用
- 在引导选择组件中的搜索不起作用,其中数据令牌包含所有数字;4730”;
- JQuery UI 地图搜索不起作用
- 谷歌地图地点搜索框不起作用
- 搜索按钮不起作用
- jQuery搜索和替换不起作用(Wordpress)
- 不区分大小写的字符串搜索不起作用
- 引导表分页和搜索不起作用
- ajax实时建议搜索不起作用
- jQuery mobile折叠列表视图,搜索不起作用
- Angular在ng-repeat中的搜索不起作用
- 实时搜索不起作用
- 选择2 4.0 JSON搜索不起作用
- JS,在数组中搜索不起作用
- 为什么我的即时搜索不起作用