1 var user = form.name.value; 2 var password = form.password.value; 3 var url = "chkname.php?user="+user+"&password="+password;//以前只知道ajax用於對用戶名的檢測,原來還可以對密碼進行檢測。 4 xmlhttp.open("GET",url,true); 5 xmlhttp.onreadystatechange = function(){ 6 if(xmlhttp.readyState == 4){ 7 var msg = xmlhttp.responseText; 8 if(msg == '1'){ 9 alert('用戶名或密碼錯誤!!'); 10 form.password.select(); 11 form.check.value = ''; 12 code(form); 13 return false; 14 }if(msg == "3"){ 15 alert("用戶名被占用,請重新輸入!"); 16 return false; 17 }else{ 18 alert('歡迎光臨'); 19 location.reload(); 20 } 21 } 22 } 23 xmlhttp.send(null); 24 return false;
第一步需要一個 jq的js文件
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/public/js/jq1.7.js"></script>
<script language="javascript">
$(document).ready(function(){
$("#submit").click(function(){
if( $("#uname").val() == "" || $("#upas").val() == "" ){
alert("用戶名或者密碼不能為空");
return false;
}else{
$("#showerrormessage").load(
'<?php echo $this->baseUrl ?>/index/login',
{uname:$("#uname").val(),upas:$("#upas").val()},
function(data){
if(data == 1){
$("#showerrormessage").html('login success!!!');
}else{
$("#showerrormessage").html('login error~~~');
}
}
);
}
});
});
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
用戶名:<input type="te......余下全文>>
Ajax我會.但JSP我只是個半吊子