ライブ結果を表示する検索エンジンを持っていますが、2番目の機能があります。これは、送信ボタンをクリックして結果ページにリダイレクトされます。 アクションで私のライブサーチ(まだデモ版)が があり、そのためのコードがあります:2つの検索エンジン機能を組み合わせる方法
jQuery(document).ready(function ($) {
\t $("#food_search").keyup(function(event){
\t \t var search_term =$(this).val();
$.ajax({
\t type:"POST",
\t url:"http://page.com/bg/%D1%82%D1%8A%D1%80%D1%81%D0%B5%D0%BD%D0%B5-%D0%BD%D0%B0-%D1%85%D1%80%D0%B0%D0%BD%D0%B8/",
\t data:{'fsearch':search_term},
\t success:function(res){
\t \t $("#food_search_result").html(res);
\t \t console.log(res);
\t },
\t error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(xhr.responseText);
alert(thrownError);
}
});
\t });
});
<!----------------------------------------------------------------
HTML
----------------------------------------------------------------->
<form method="post" accept-charset="utf-8">
<input type="text" name="fsearch" id="food_search">
<button id="search-button" type="submit"><i id="button-icon"></i><span id="button-text">Търсене..</span></button>
</form>
<div id="food_search_result">
<?php
If(isset($_POST['fsearch'])){
var_dump($_POST['fsearch']);
}
// printing the results here in my div(for live search)
?>
</div>
<!----------------------------------------------------------------
PHP
----------------------------------------------------------------->
<?php /*Template Name:Food-Search.php*/ ?>
<?php
$hostname = "localhost";
$username = "name";
$password = "password";
$databaseName = "DB NAME !";
$connect = new mysqli($hostname, $username, $password, $databaseName);
$connect->set_charset("utf8");
$fsearch= "";
if(!empty($_POST['fsearch'])) {
$fsearch =$_POST['fsearch'];
$req = $connect->prepare("SELECT title FROM food_data_bg WHERE title LIKE ?");
$value = '%'.$fsearch.'%';
$req->bind_param('s', $value);
$req->execute();
$req->store_result();
$num_of_rows = $req->num_rows;
$req->bind_result($title);
if ($req->num_rows == 0){
echo 'Няма резултати';
}
else{
while($data=$req->fetch()){
?>
<div class="search-result">
<span class="result-title"><?php echo $title; ?></span>
</div>
<?php
}
var_dump($_POST['fsearch']);
$req->free_result();
}
}
申し訳ありません私はあなたが混乱している場合、私はかなりあまりにも笑って混乱しています。ありがとう!
私はそれが間違いなく助けになりますが、私はユーザーにリダイレクトするページの結果を見たいと思います。リダイレクトされたページで印刷されるデータベースの一致結果が必要です.THANKS <3 –