im trying to make live search , the data calls back from ajax call , and i want to put that data to my search function , but i cant access to the ajax data to make the search
function returnVistors(){
k = '';
$.ajax({
type:'GET',
url:'/my-url/list',
success:function(data){
visitors = data.visitors
document.getElementById('spinner').classList.add('non-visible')
for(i = 0;i < visitors.length; i++){
const id = visitors[i]['id']
const detail_url = '{% url "vistors:vistor_obj" id=1111 %}'.replace(/1111/,parseInt(id));
k+='<a href="'+detail_url+'" class="flex hover:bg-purple-900 hover:text-white items-center border rounded-xl mt-1 p-2"></a>';
k+='<p class="mr-2">'+visitors[i]['full_name'] + ' - '+ visitors[i]['city']+'</p>'
}
document.getElementById('visitors_results').innerHTML = k
},
});
return k
}
<div id="visitors_results" class="p-3 bg-white rounded-xl mt-4 md:mt-5 p-2 overflow-y-scroll">
<div class=" flex justify-center items-center" id="spinner">
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-gray-900"></div>
</div>
</div>
returns nothing also , i tried to console.log(returnVistors())
it also shows nothing ?!
thank you for helping