Why redirect doesn't work

I don’t use the Django form, but save data via AJAX. How do I go to another page after saving, for example, ‘home’? It doesn’t work that way…

def JurnalOst(request):
    podraz = Podraz.objects.get(pk=74)
    postav = Postav.objects.get(pk=9)
    obct = Obct.objects.get(pk=180)
    fio = Fio.objects.get(pk=5)
    jurnalost=Jurnal.objects.filter(oper=1)
    if request.method=='POST':
        nomerdoc1=request.POST['nomerdoc']
        datadoc1=request.POST['datadoc']
        print(nomerdoc1,datadoc1)
        newost=Jurnal()
        newost.nomerdoc=nomerdoc1
        newost.datadoc=datadoc1
        newost.podraz=podraz
        newost.postav=postav
        newost.obct=obct
        newost.fio=fio
        newost.oper=1

        newost.save()
        un = Jurnal.objects.values()
        unit_data=list(un)
        #return JsonResponse({'status':1,'unit_data':unit_data})
        return reverse('home')
urlpatterns=[
   path('', loginUser, name='loginUser'),
   path('main/',index,name='home'),
]

Sorry, “return redirect(‘home’)”. But it doesn’t work either

ajax

<script>
console.log('Script running!');
$('#ost-form').on('submit',function(e){
event.preventDefault();
let _nomerdoc=$('#id_nomerdoc').val();
let _datadoc=$('#id_datadoc').val();
let _csr=$("input[name=csrfmiddlewaretoken]").val();

mydata={
nomerdoc:_nomerdoc,
datadoc:_datadoc,
csrfmiddlewaretoken:_csr,
}



console.log('Pressed');
console.log(_nomerdoc);
console.log(_datadoc);
console.log(mydata);

$.ajax({
url:'/JurnalOst/',
method:"POST",
data:mydata,
dataType:"json",

success:function(data){
if (data.status==1){
console.log(data.unit_data);
console.log('saved');

}
}

});
});
</script>

You would need to handle the redirect response in your JavaScript code.

One of the purposes of AJAX is to prevent the browser itself from going to a new page on the received response. Any page navigation is up to the JavaScript code handling it.

However, if you want the AJAX to send you to a new page, it’s a lot easier to add something like a “next-page” key in the JSON response and have your code handle that than to have it follow a 302 response.