send url to ajax's success () from Django backend -
i want send data html view django backend process , backend send url html view redirect user page. it's this:
page 1 ----user's input data --- ajax --- > backend --- process --- url page 2 --- ajax --> page 2
the problem that, don't know how send url ajax after processing user's data, have redirect using window.location.href = '/' . think code not clean way. wonder if there way send url ajax's success backend.
here code n html :
function dosomething(data){ $.ajax({ type: "post", url: url_post_by_ajax, data: { 'data' : data, }, success: function (response) { window.location.href = '/'; }, error: function (data) { alert('failed'); } });}
please me. thank you!
in processing view:
from django.http.response import jsonresponse def whatever_your_view_name_is(request): (data processing...) return jsonresponse({'url': the_url_to_page_2)
then in js:
(...) success: function (response) { window.location.href = response.url; }, (...)
Comments
Post a Comment