javascript - Two ajax post calls with one submit button -
is possible do? 1 post call. want post call username/password , 1 email/password 1 submit button. if both succeeds, redirecting page best.
ajax call jquery:
$('form').submit(function() { $.ajax({ type: "post", url: $('form').attr('action'), data: $(this).serialize(), success: function(data, status, xhr) { alert("login successful. redirecting"); window.settimeout(function() { window.location.href = "3.3.3.3/login" }, 5000); }, error: function(data, status, xhr) { $('form').trigger("reset"); alert("failed login. please try again."); } }); return false; alert("ajax request completed"); });
<html> <head> <title>log in</title> <link rel="stylesheet" href="static"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> </head> <body> <form action="1.1.1.1/login" method="post"> <div class="login"> <div class="login-screen"> <div class="app-title"> <h1> login</h1> </div> <input class="form-control" type="text" required name="username" placeholder="username"> <input class="form-control" type="password" required name="password" placeholder="password"> <input class="form-control" type="hidden" required name="eauth" value="pam"> <input class="form-control" type="text" required name="email" placeholder="email"> <p> <input type="submit" value="log in" /> </p> </div> </div> </form> </body> </html>
yes it's possible. figure there bad backend choices there if have check 2 different pages figure out if user can proceed?
but apart that... run 2 ajax calls after each other. run async, , have little control on finish first, should have bool, firstajaxhassucceeded, true after either of ajax calls succeed. , if it's true, transfer user other page (both ajax calls should check also).
edit
pseudo code (don't have time else):
var firstajaxhassucceeded = false; firstajaxcall() { var success = verifythisajaxanswer(); if (firstajaxhassucceeded && success) { //transfer next page, yeay!! } firstajaxhassucceeded = true; } secondajaxcall() { var success = verifythisajaxanswer(); if (firstajaxhassucceeded && success) { //transfer next page, yeay!! } firstajaxhassucceeded = true; } firstajaxcall(); secondajaxcall();
Comments
Post a Comment