0

I am trying to render the template called reset_password_page.html using AJAX. I intend to send some data to this template. The problem is that page is not getting loaded. It gets loaded when I use location.href, but this cannot be used as I won't be able to send any data to the template.

function trial() {
  if ("{{ verified }}" == "yes") {

   document.getElementById('lbl_verify').style.display = "block";
   document.getElementById('lbl_verify2').style.display = "none";

    window.setTimeout(function() {
      $(document).ready(function() {
        $.ajax({
          url: "{% url 'reset_password_page' %}",
          type: "POST",
          data: {
            csrfmiddlewaretoken: '{{ csrf_token }}'
          },
          async: false,

        });
      });

    }, 1000);

  } else {

  }
}

views.py

def reset_password_page(request):
  return render(request,"reset_password_page.html")
6
  • if ("{{ verified }}" == "yes") { will never be true because it is just comparing string Commented May 6, 2019 at 6:06
  • It is working because I tested it with 'alert' . verified is a variable from the view.py .Up to that point the code is correct. Commented May 6, 2019 at 6:08
  • Please show the alert code Commented May 6, 2019 at 6:09
  • I edited the code . The style changes in my code actually take place. only the ajax is not working. Commented May 6, 2019 at 6:12
  • What does {% url 'reset_password_page' %} evaluate to? Commented May 6, 2019 at 6:18

1 Answer 1

1

Its due to the if condition used.You are comparing if ("{{ verified }}" == "yes") which is false. try if ({{ verified }} == "yes") which will fetch verified value.

Sign up to request clarification or add additional context in comments.

1 Comment

I edited the code . The style changes in my code actually take place. only the ajax is not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.