有关PHP做弹出式登陆框口的代码
发布网友
发布时间:2022-04-06 10:13
我来回答
共2个回答
热心网友
时间:2022-04-06 11:42
给你秀一下我写的AJAX代码,
至于"怎么读到数据库的方法说出来",一般在后台完成,谁会把数据库结构摆在你面前,这不是找死?!
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- script type='text/javascript' src='./jscode/loginAjax.js'></script -->
<script language='javascript'>
function login(){
var
str = getformvalues("formlogin");
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username == ""){
alert("请输入姓名");
return false;
}
if (password == ""){
alert("请输入密码");
return false;
}
makerequest("respond/login.php", "error_mes", "POST", str);
}
function sel(){
so.submit();
}
function getxmlhttp(){
var xmlhttp = false;//初始化xmlhttp.
try{
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
//alert('IE');
}catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//alert('IE also !');
}catch(e){
xmlhttp = false ;
}
}
if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
xmlhttp = new XMLHttpRequest() ;
//alert('Not IE!');
}
return xmlhttp;
}
function makerequest(serverPage, divId, getOrPost, str){
//var obj = document.getElementById("error_mes");
var username = document.getElementById("username").value;
var result;
var xmlhttp = getxmlhttp();
if(!xmlhttp){
alert("您的浏览器好象未开启Ajax,可能无法体验本站的全部功能!");
formlogin.submit();
return false;
}
if(getOrPost == "get"){
xmlhttp.open("GET",serverPage);
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}else{
xmlhttp.open("POST",serverPage,true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
result = xmlhttp.responseText;
checkrequest(result, username);
}
}
xmlhttp.send(str);
}
}
function getformvalues(formid){
var formObj = document.getElementById(formid);
var str = '';
for(var i = 0; i<formObj.elements.length; i++){
str += formObj.elements[i].name +"="+escape(formObj.elements[i].value)+"&";
}
return str;
}
function checkrequest
(re, username){
var str;
var obj = document.getElementById("error_mes");
if(re == '-1'){obj.innerHTML = '输入为空'
;}
if(re == '1'){obj.innerHTML = '密码错误';}
if(re == '2'){obj.innerHTML = '用户不存在';}
if(re == '0'){
//alert('登陆成功!');
str = "<div align='right'>欢迎用户:<font color='#FF9900'>"+username+"</font> ";
str += "<a href='manage.php'>控制面板</a> <a href='login.php?action=exit'>退出登录</a></div>";
document.getElementById("showmes").innerHTML = str;
}
}
</script>
<body>
<table width='65%' border='0' align='right' cellpadding='0' cellspacing='0'>
<form action='login.php?action=login' method='post' name='formlogin' id='formlogin'>
<tr>
<td width='20%'><div id='error_mes'></div></td>
<td width='15%'> <div id='user' align='center'>用户</div></td>
<td width='25%'>
<input name='username' type='text' class='input' id='username' maxlength='10'></td>
<td width='12%'> <div id='psw' align='center'>密码</div></td>
<td width='25%'>
<input name='password' type='password' class='input' id='password' maxlength='10'
onkeydown="if(event.keyCode==13) login();"></td>
<td width='12%'>
<div align='center'>
<a style='cursor:hand' onclick='return login()'>
<img src='images/index_06.jpg' width='37' height='21' border='0'></a>
</div></td>
<td width='12%'>
<div align='center'>
<a href='register.php'>
<img src='images/index_08.jpg' alt='' width='37' height='21' border='0'></a>
</div></td>
</tr>
</form>
</table>
</body>
</html>
参考资料:http://etongchina.blogcn.com
热心网友
时间:2022-04-06 13:00
只需要AJAX技术.....