PHP Login with jQuery AJAX
body, input {
font-family: Georgia, “Times New Roman”, Times, serif;
}
#content {
background-color: #eee;
width: 300px;
margin: 0 auto;
border: 1px solid #aaa;
-moz-border-radius: 10px;
-moz-box-shadow: 0 0 10px #aaa;
-webkit-border-radius: 10px;
-webkit-box-shadow: 0 0 10px #aaa;
padding: 10px;
}
#form1 label {
display: block;
font-size: 16px;
line-height: 25px;
}
#form1 input[type=text], #form1 input[type=password] {
padding: 2px;
font-size: 16px;
line-height: 20px;
width: 250px;
}
#form1 input[type=submit] {
font-size: 20px;
font-weight: bold;
padding: 5px;
}
.success {
color: #060;
}
.error {
color: red;
}
$(document).ready(function() {
$(“#login”).click(function() {
var action = $(“#form1”).attr(‘action’);
var form_data = {
username: $(“#username”).val(),
password: $(“#password”).val(),
is_ajax: 1
};
$.ajax({
type: “POST”,
url: action,
data: form_data,
success: function(response)
{
if(response == ‘success’)
$(“#form1”).slideUp(‘slow’, function() {
$(“#message”).html(“
You have logged in successfully!
“);
});
else
$(“#message”).html(“
Invalid username and/or password.
“);
}
});
return false;
});
});
Login Form
Username:
Password: