title: request.is_ajax() ajax request not working in django
body: <p>In the following code, I am getting redirect to this text <strong>{'saved': 1}</strong> instead of the template which is rendered by the view, here, I used <strong>request.is_ajax()</strong> function. and I am using Django Version: 3.1.1</p>
  <p><strong>Views.py</strong></p>
  <pre><code>def add_Patient(request):
      if request.is_ajax():
          add = Patient(
              name=request.POST['name'],
              gender=request.POST['gender'],
              birthdate=request.POST['birthdate'],
              age=request.POST['age']
          )
          add.save()
          return JsonResponse({'saved': 1})
      return render(request, 'Patient_template/add_patient.html')
  </code></pre>
  <p><strong>add_patient.html</strong></p>
  <pre><code>&lt;script&gt;
          const form = document.getElementById(&quot;patient&quot;);
          form.addEventListener(&quot;submit&quot;, submitHandler);
  
          function submitHandler(e){
              e.preventDefault();
              $.ajax({
                  url : {% url 'Patient:add' %},
                  type : 'POST',
                  data : $(&quot;#form&quot;).serialize(),
                  dataType: 'json',
                  success: function(msg){
                      if (msg.saved === 1){
                          alert(&quot;Data Saved&quot;);
                          form.reset();
                      }
                  }
              });
          }
  &lt;/script&gt;
  </code></pre>
  <p>So help me to find an alternative solution or solve this problem.</p>