Базовый HTML:
<form id="login-form" action="/login.php" method="post">
<label for="username">Username: </label>
<input type="text" name="username" id="username"/><br />
<label for="Password">Password: </label>
<input type="text" name="password" id="password"/><br />
<input type="submit" value="Login"/>
</form>
Базовый jQuery:
$(document).ready(function() {
$('#login-form').bind('submit', function (e) {
var self = $(this);
// See ajax: http://api.jquery.com/jQuery.post
// See serialize: http://api.jquery.com/serialize()
jQuery.post(self.attr('action'), self.serialize(), function () {
if (response.success) {
// wooo, logged in
} else {
alert("Invalid username or password. Please try again");
}
}, 'json');
e.preventDefault(); //prevent the form being posted
});
});
Базовый PHP:
<?php
if ($_POST['username'] == 'Admin' && $_POST['password'] == 'letmein') {
echo json_encode(array('success' => true));
} else {
echo json_encode(array('success' => false));
};
?>
Немного проверки данных не сработает.