javascript - Redirection authentication form in PHP when preventDefault is used -


I have an authorization form in an HTML page and to check that the user / password are correct or not. I want to call my PHP script with jquery ajax and use preventDefautlt to avoid reloaded page effects.

What do I have to do: User / password redirects the right user to the authorized page, if not the error message is not displayed. My question is, should the user have to redirect the header function from my PHP script or from javascript when the user / password is correct? What is safe to redirect form JS?

  $ ("#signin"). Submit (function) {event.preventDefault (); var $ form = $ (this), url = $ Form.attr ("verb"); console.log ($ form.serialize ()); var posting = $ .post (url, $ form.serialize ()); posting.done (function) {if (data == "LOGGED-IN") {// redirection;} and if (data == "USER-PASSWORD- KO ") {// display error message} console.log (data); // $ (" # login-dialog ") .append (data);});});  

You have to do it like javascript,

  Posting.done (function {if (data == "LOGGED-IN") {window.location.href = 'home.php'; // You want to redirect it to home.php} Otherwise if ( Data == "USER-PASSWORD-KO") {Warning ('Invalid user name / password')} console.log (data); // $ ("# login-dialog") .append (data);});  

And if you are sending a username and password using js then there is no need for redirection again.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -