15 Django E Commerce Autocomplete in Search by Using AJAX JQuery [English]

preview_player
Показать описание
Autocomplete in Search by Using AJAX JQuery
Рекомендации по теме
Комментарии
Автор

The best django ecommerce course I've ever taken! thanks so much Yuksel! you rock!

franmed
Автор

in the script code
i tried using a django url like this, but it does not work.
<script>
$(function() {
$("#query").autocomplete({
url: "{% url 'shop:search_auto' %}",
select: function (event, ui) { //item selected
AutoCompleteSelectHandler(event, ui)
},
minLength: 2,
});
});

function AutoCompleteSelectHandler(event, ui)
{
var selectedObj = ui.item;
}
</script>
any solutions

toluwanimiadeyemo
Автор

Sir I have no idea what I am doing wrong. I created a simple form to test the auto complete.
<div class="container">
<form action="/trial/" method="GET">
{% csrf_token %}
<input type="text" id="Name">
<input type="button" value="submit">
</form>
I followed the steps to add the jQuery script but I keep getting 'fail'. This is my view. Name is my model.

def trial(request):
if request.is_ajax():
q = request.GET.get('term', '')
names =
results = []
for pr in names:
name_json = {}
name_json = pr.name
results.append(name_json)
data = json.dumps(results)
else:
data = 'fail'
mimetype = 'application/json'
return HttpResponse(data, mimetype)


Any guidance would really be appreicated

motlatsimoea