I have a simple AJAX script that takes an input string into a search field with a name AJAXBoxand calls a view function that queries the database with a filter and returns a set of queries for all User objects that match the input parameter. When I go through iteration through a set of queries with django template tags, it doesn't work. I assume this is because the output for my Javascript request does not actually output a set of requests, but some type of string that the django template does not recognize. How can I fix this so that my AJAX calls return true django-compatible requests that perform the normal rendering function in django outputs?
JS for AJAX:
$(document).ready(function(){
$('#AJAXBox').keyup(function() {
var searchedterm;
searchedterm = $(this).val();
$.get('/AJAXsearch/', {searchterm: searchedterm}, function(data){
$('#result').html(data);
});
});
});
For tp; dr for python code essentially:
def AJAXsearch(request):
searchterm = request.GET['searchterm']
result = UserObj.objects.filter(person_name=searchterm)
return HttpResponse(result)
html - :
<div id="result">
{% for person in result %}
{{person.property}}
{%endfor%}
</div>
. , / , .