jQuery $.post window.location redirect not working in .done

Edit There is something wrong as the inside of the .done callback does not execute, even a simple alert('something');

I've noted the error pointed out by Sverri I should note that this script is included externally, maybe that's the problem?

The login is successful, if I refresh the same page that I'm on, I am redirected by the PHP session catch at the top page. I'm trying to avoid having the login stuff for PHP on the same page as the form, but rather include it as a separate page.

When I process this, within the .done catch, the redirect does not work. I am logged in, the process works without errors. That's why when I refresh the same page(login) a session exists so I'm redirected by the php redirect.

$.post("login.php", {
  'variable1':$variable1,
  'variable2':$variable2
}).done(function() {
  window.location = "next-page-url";
}
});

UPDATED

$.post("login.php", {
  'variable1':$variable1,
  'variable2':$variable2
}).done(function() {
  window.location = "next-page-url";
});

Answers 1

  • Your code has no major issue, as in just check other callback functions, like 'fail' or direct callback.

      <script>
        $(document).ready(function() {
          alert("hello");
          $.post("/", {
            "var": "hello",
            "bar": "qwerty",
          }).done(function() {
            alert("hello !!");
          }).fail(function() {
            window.location = "www.google.co.in";
          });
        });
      </script>
    

Related Articles