Answer the question
In order to leave comments, you need to log in
How to pass an array via json and return an array?
I have a task to transfer an array to a view, and from there back in an array.
it looks like this for me (does not work):
js
var arr_obj = [5, 7, 23, 99, 21, 29];
$.ajax(
{
type: "GET",
url: "{% url 'likepost' %}",
// dataType: 'html',
// cache: false, // запретит браузеру кешировать
data : JSON.stringify({
post_id: arr_obj
}),
dataType: "json",
success: function(data) {
alert(data)
}
})
def likePost(request):
if request.method == 'GET':
post_id = request.GET['post_id']
return HttpResponse(post_id)
else:
return HttpResponse("Is not a GET")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question