I think the best way to do that is to submit the form via-ajax and get a JSON reply from the server.. so:
The javascript:
$(document).ready(function(){
$("#my-jq-form").submit(function(){
// Prepare URL and data
url = $(this).attr("action");
parm_name = $("#input-name").val();
parm_psw = $("#input-psw").val();
jQuery.get(url, {
'name' : parm_name,
'psw' : parm_psw,
}, function (data, textStatus){
$("#message").html(data.message)
if (data.status) {
$("#message").css('color', "#0f0")
} else {
$("#message").css('color', "#f00")
}
}, "json");
return false; // block form submitting
});
});
The HTML form:
<form id='my-jq-form' method='GET' action="http://webdocs.samu.local/esperimenti/jquery-ajax/jqlogin-req.php">
<table cellpadding="0" border="0">
<tr>
<td align="right">name/email:</td>
<td align="left"><input type="text" id="input-name" name="name" /></td>
</tr>
<tr>
<td align="right" valign="top">password:</td>
<td align="left"><input type="text" id="input-psw" name="psw" /></td>
</tr>
<tr align="center">
<td></td>
<td><span id="loginErr"></span></td>
</tr>
<tr>
<td> </td>
<td><button type='submit' name='submit'>Login</button></td>
</tr>
</table>
</form>
<div id="message"></div>
Then, you can generate the JSON serverside using something like (in php):
<?php
/*
Simple Ajax login management:
replies via-JSON with login status informations, plus a message
that will be shown to user
*/
$login_user = $_GET['name'];
$login_pass = $_GET['psw'];
$my_user = "admin";
$my_pass = "mypass";
if ($login_user == $my_user && $login_pass == $my_pass) {
$login = TRUE;
$status="true";
$message="Login Successful. Welcome $my_user into systems. ".date("Y-m-d H:i");
} else {
$login = FALSE;
$status="false";
$message="Login failed. Wrong username/password.";
}
header("Content-Type: text/javascript; charset=utf-8");
echo "{ \"status\": $status, \"message\": \"$message\" }";
..hope that helps. For more info, see http://docs.jquery.com/Ajax/jQuery.get