スクリプトコードに問題があります。私は検索の結果を表示する警告ボックスを持っていますが、問題はそれが現在のものではなく前の結果を表示していることです。初めてnullを返すときは、前の結果を与えることで動作します。なにが問題ですか? 。あらかじめおねがいします。警告ボックスの不具合
<?php
include_once('dbconnect.php');
if(isset($_POST['search'])){
$q = $_POST['q'];
$query = mysqli_query($conn,"SELECT * FROM `users` WHERE userCountry LIKE '%".$q."%'");
//Replace table_name with your table name and `thing_to_search` with the column you want to search
$count = mysqli_num_rows($query);
if($count == "0" || $q == ""){
$output = '<h2 style="color:white;">No player found!</h2>';
}else{
while($row = mysqli_fetch_array($query)){
$s[] = $row['userIngame']; // Replace column_to_display with the column you want the results from
$output = '<h2 style="color:white;">There are '.$count.' players </h2><br>';
}
}
}
echo json_encode($s);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(document).ready(function(){
$("form").submit(function(){
var player = <?php echo json_encode($s); ?>;
alert("players : " + player);
});
});
</script>
あなたは何を期待していますか?私はあなたのページがちょうどリロードし、それが前の検索の結果を表示する理由だと思います。 –
'$(document).ready'の警告を' form.submit'で表示しないようにしてください。 –
@u_mulderはいです。それを修正する方法を教えてください。 – Peslis