I am creating a search box using Flask, MySQL, and ajax
.
I am getting the JSON format of search results in the console but I want to append it on my option value in datalist
in my HTML.
Here is the HTML -
<form class="cours-search">
<div class="input-group">
<input type="text" class="form-control" id="searchbox" autocomplete="off" placeholder="Search Address, Owner Name " name="city" list="results">
<datalist id="results">
<option value="Boston">
</datalist>
<div class="input-group-append">
<button class="btn" type="submit">Search</button>
</div>
</div>
</form>
Here is my ajax code -
<script>
$(document).ready(function(){
$("#searchbox").on("input", function(e){
searchtext = $("#searchbox").val();
$.ajax({
method:"post",
url:"/searchengine",
// data:{backendname:valueName}
data:{text:searchtext},
success:function(res){
console.log(res);
//What Should I Do I Don't Know
}
})
});
})
</script>
Here is the Result Data in Console (in JSON Format) -
0: {address: "Delhi NCR"}
1: {address: "Dhar"}
length: 2
__proto__: Array(0)
I want to add address value in datalist <option>
in my HTML .
Thank you so much in advance.