<script type="text/javascript"> //button click function sendData() { if (jQuery.trim($('#username').val()) == "") { alert("Please type the username."); $('#username').focus(); return false; } if (jQuery.trim($('#password').val()) == "") { alert("Please type the password."); $('#password').focus(); return false; }
IE:xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
FF:xmlHttp=new XMLHttpRequest();
先open("get/post"url,true),再给xmlHttp的onreadystatechange属性赋值,最后send(null).
<script type="text/javascript">
//button click
function sendData() {
if (jQuery.trim($('#username').val()) == "") {
alert("Please type the username.");
$('#username').focus();
return false;
}
if (jQuery.trim($('#password').val()) == "") {
alert("Please type the password.");
$('#password').focus();
return false;
}
//ajax post
$.post("your url",
{username: jQuery.trim($('#username').val()), password: jQuery.trim($('#password').val())},
function() {
$("#username").val("");
$("#password").val("");
}
);
}
</script>
<ul class="list">
<li><label for="username">User Name:</label><input id="username" name="username" type="text" required="true" tip="Please input your login name." /></li>
<li><label for="password">Password:</label><input id="password" name="password" type="password" required="true" tip="Please input your password." /></li>
<li><center><input id="btnSignCheck" style="width:60px" type="button" value="Login" onclick="sendData();"/></center></li>
</ul> $username = $f->filter($this->getRequest()->getParam('username'));
$password = $f->filter($this->getRequest()->getParam('password'));
//验证用户名与密码,代码略