Php file
<?php global $ajax_recieve;
if(isset($_POST['values'])){
$ajax_recieve = $_POST['values'];
}
$result = mysqli_query($read_info,"SELECT Namn FROM information WHERE Namn LIKE ('".$ajax_recieve.'%")";
$resultSet = array();
while($row = mysqli_fetch_array($result)) {
$resultSet[] = array( 'Name'=> $row['Namn']);
}
$json = json_encode($resultSet);
echo $json;
?>
JS file
$(document).ready(function(){
$('#search').on('input', function() {
var inputSearch = $('#search').val();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: 'json',
url: "createJSON_list.php",
data: {values: inputSearch},
success: function(response){
$.each(response, function(){
$('#json_datalist').append(response[0]);
console.log(response[0]);
});
}
});
});
});
I cannot see value in console.log. Or I get only last data from database. I need a array which must be append to a html datalist as an array.
Solved
contentType: "application/json; charset=utf-8", Removed this row and changed this
$.each(response, function(key,Val){$('#json_datalist').append(“<value=‘“+Val.Name”’+”>”);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.