Ich habe ein Login-Formular, das immer auf eine neue Seite geladen wird, wenn ein Fehler auftritt, zB 'E-Mail-Adresse nicht registriert'. Ich brauche die Fehler, um auf derselben Seite anzuzeigen, ohne auf eine neue Seite neu zu laden. Ich folgte einem Tutorial, wie man es mit Ajax macht, aber es scheint nicht zu funktionieren, die Seite lädt noch neu. Der Ajax-Code ist:Ajax zeigt Fehler im Login-Formular an, ohne die Seite erneut zu laden
$("#login_button").click(function(){
$.post($("#login_form").attr("action"), $("#login_form :input").serializeArray(), function(info){$("#login_errors").html(info);});
clearInput();
});
$("login_form").submit(function(){
return false;
});
function clearInput(){
$("#login_form: input").each(function() {
$(this).val('');
});
}
Mein Code für mein Login-Formular ist:
<form id= "login_form" action="login.php" method="post">
<span id="login_errors"></span>
<label>Email Address</label>
<input type="text" name="email" id="email" required="required"/>
<br />
<label>Password</label>
<input type="password" name="password" id="password" required="required"/>
<br />
<div class="checkbox">
<input id="remember" type="checkbox" />
<label for="remember">Keep me signed in</label>
</div>
<div class="action_btns">
<div class="one_half last"><input type="submit" class="btn btn-blue" id="login_button" value="Login"></div>
<div class="one_half last"><a href="#" id="register_form"
class="btn">Sign up</a></div>
</div>
</form>
Und ich den Ajax-Skript verknüpft mit:
<script type="text/javascript" src="login_Ajax.js"></script>
funktioniert immer noch nicht:/ – jollyroger
so klicken Sie auf die Schaltfläche, und die Seite neu geladen wird? –
Vergessen Sie nicht, gute alte https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault – Terminus