Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <form action="" method="post" id="form1">
- <input type="text" name="fname" id="fname" value="fname value">
- <input type="text" name="lname" id="lname" value="lname value">
- <input type="button" value="Submit" id="submit">
- </form>
- <form action="" method="post" id="formError">
- <input type="text" name="fname" id="fname" value="fname for error form">
- <input type="text" name="lname" id="lname" value="lname for error form">
- <input type="button" value="Submit For Errors" id="submitError">
- </form>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous"></script>
- <script src="./helpers.js"></script>
- <script>
- $(document).ready(function() {
- $("#submit").on("click", function(event) {
- Ajax.post(event, $("#form1"), "dest.php", processResponse);
- });
- $("#submitError").on("click", function(event) {
- Ajax.post(event, $("#formError"), "error.php", processResponse);
- });
- });
- function processResponse(response) {
- if (response.failed) {
- console.log("Authentication failed!");
- // throw new Error("Authentication failed!"); // throwing will return out of processResponse no need to return if this will be caught somewhere else
- return null; // for demo purposes, or if the throwing is not the desired result
- }
- console.log("Response...", response);
- let now = new Date();
- now.setTime(now.getTime() + (30 * 24 * 60 * 60 * 1000))
- document.cookie = 'session_key=' + response.session_key + '; expires' + now.toUTCString();
- console.log('Autentificat cu succes! Cheie: ', response.message);
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment