我已经尝试过stackoverflow和其他网站上的这么多方法,但每当我成功隐藏div时。根本没有显示搜索结果。
我已经尝试过:空选择器和摆弄PHP代码和js代码。但由于我对此非常新,我似乎无法破解错误。我做错了什么?
我的HTML
<div class='search'>
<form class="searchbox" action='index.php' method='post' autocomplete='off'>
<input type='text' name='search' class='searchform' placeholder='Søg efter skole...' onkeyup="searchq();">
</form>
<div id="output"></div>
</div>
PHP
<?php
include("connection.php");
$output = '';
//collect
if(isset($_POST['searchVal'])) {
$searchq = $_POST['searchVal'];
$searchq = preg_replace("#[^a-zA-Z0-9æøå]#i"," ", $searchq);
$query = mysqli_query($mysqli, "SELECT * FROM `products` WHERE name LIKE '%$searchq%'") or die("could not search");
$count = mysqli_num_rows($query);
if($_POST['searchVal'] == NULL) {
$output = '';
} else {
while($row = mysqli_fetch_array($query)) {
$name = $row['name'];
$id = $row['id'];
$output .= '<a href="kantine.php?id='.$id.'" class="searchres">'.$name.'</a><br>';
}
}
}
echo "<div class='output'>$output</div>";
?>
和JS
function searchq() {
var searchTxt = $("input[name='search']").val();
$.post("search.php", {
searchVal: searchTxt
}, function(output) {
$("#output").html(output);
});
}
答案 0 :(得分:1)
<强> HTML 强>
function app_cmd(cmd, args,path) {
const ls = spawn ( cmd , args , { cwd : path } );
console.log ( cmd +' ' + ls.pid );
ls.on ( 'close' , function(code) {
console.log ( 'returning: ' + code + ' on ' + ls.pid );
} );
return ls.pid;
}
<强> PHP 强>
<div class='search'>
<form class="searchbox" action='index.php' method='post' autocomplete='off'>
<input type='text' name='search' class='searchform' placeholder='Søg efter skole...' onkeyup="searchq();">
</form>
<div id="output" style="display: none;"></div>
</div>
<强> JS 强>
.....
echo $output;