django request ajax code example
Example 1: django ajax without jquery
from django.http import JsonResponse
def get_random_number_json(request):
random_no = random.randint(1,100)
return JsonResponse({'random_no': random_no})
Example 2: ajax django send array
$('.btn-group').find('#mark_as_done').on('click', function() {
var tasks = grab_selected();
$.ajax({
type: 'POST',
url: '/edit_lists/',
data: {'tasks[]': tasks},
});
});