I have jQuery Ajax Autosuggest using jSon.
Now I have problem when showing the data. The data get from mysql data using PHP (looping data) but when get the result, it always show 1 row.
Here is my js code:
$.ajax(
{
type: "GET",
data: post_string,
dataType: "json",
cache: false,
url: 'search.php',
success: function(data)
{
full_name = data[0].full_name;
username = data[0].username;
$("#divResult").show();
$(".display_box").html(username);
}
});
and the search.php
$getSearchWord = mysqli_real_escape_string($con, $_GET['searchword']);
$json = array();
$searchQuery = mysqli_query($con, "SELECT * FROM tb_users WHERE username LIKE '%$getSearchWord%' OR full_name LIKE '%$getSearchWord%' LIMIT 5");
while($searchFetchData = mysqli_fetch_array($searchQuery))
{
$json[] = array(
'username' => $searchFetchData['username'],
'full_name' => $searchFetchData['full_name']
);
}
echo json_encode($json);
and html div to display
<div id="divResult">
<div class="display_box"></div>
</div>