javascript读取xm子节点,无刷新例子(javascript,xml,php)
下面这个javascript 函数是用来做无刷新判断用户名和密码是否正确
<script language= "javascript">
function login_sussess(){
var flag = false;
var user,psw;
user = form1.user.value;
psw =form1.psw.value;
coder = form1.coder.value;
form1.submit2.disabled ="false";
document.getElementById("check_result_title").innerHTML ="正在登陆...";
var oXMLDoc = new ActiveXObject(‘MSXML‘);//建立XML文档对象
sURL = "js/login_go.php?user="+user+"&psw="+psw+"&coder="+coder//载入数据页面
oXMLDoc.url = sURL; // 载入数据到对象url
var oroot = oXMLDoc.root;//读取根节点
oItem = oroot.children.item(0);
//如果还要读取oItem的子节点,应该 oItem.children.tiem(i) 就可以,以此类推
if (oItem.text == ‘1‘){
document.getElementById("check_result_title").innerHTML = "用户名或密码不正确";
form1.submit.disabled = "true";
}else if(oItem.text == ‘2‘){
document.getElementById("check_result_title").innerHTML = "验证码不正确";
form1.submit.disabled = "true";
}else if(oItem.text == ‘3‘){
document.getElementById("check_result_title").innerHTML = "登陆成功,";
location.href ="index.php";
}
}
</script>
下面这部分是login_go.php的源码:
<?php
require_once("../class/_conn.php");
if (isset($_REQUEST["user"])&&$_REQUEST["user"]) $user = trim($_REQUEST["user"]);
if (isset($_REQUEST["psw"])&&$_REQUEST["psw"]) $user = md5(trim($_REQUEST["psw"]));
if (isset($_REQUEST["coder"])&&$_REQUEST["coder"]) $coder = trim($_REQUEST["coder"]);
$flag = ‘1‘;
print("<?xml version=‘1.0‘ encoding=‘gb2312‘ ?>");
print("<plan>");
$result = $connection->My_query("select * from `members` where username = ‘$user‘ and password = ‘$psw‘",$connection->conn);
if ($row = $connection->My_array($result)){
if ($_SESSION["code"] != $coder){
$flag = ‘2‘;//验证码不正确
}else{
$flag = ‘3‘;//登陆成功
}
}
$connection->My_mysql_close($result);
echo "<result>$flag</result>";
echo ‘</plan>‘;
?>
此段php输出的xml内容是:
<?xml version="1.0" encoding="gb2312" ?>
<plan>
<result>1</result>
</plan>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。