index.php页面:
<head>
<title>Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
function chk(){
if(validate_form()==false){
return ;
}
validate() ;
} function validate_form(){
if(document.myform.name.value==""){
alert("昵称不能为空!") ;
return false ;
}
if(document.myform.pwd.value==""){
alert("密码不能为空!") ;
return false ;
}
}
var xmlHttp ;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP") ;
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest() ;
}
}
function validate(){
createXMLHttpRequest() ;
var name=document.getElementById("name").value ;
var pwd=document.getElementById("pwd").value ;
var str="name="+name+"&pwd="+pwd ;
xmlHttp.open("POST" , "indexsend.php" , true) ;
xmlHttp.onreadystatechange=callback ;
xmlHttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded") ;
xmlHttp.send(str) ;
}
function callback(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var str=xmlHttp.responseText ;
if(str=="1"){
alert("该用户存在,页面将会转向首页") ;
window.location="chating.php" ;
}
else{
alert("用户不存在或密码错误,请确认后再输入") ;
clear() ;
}
}
}
}
function clear(){
document.getElementById("name").value="" ;
document.getElementById("pwd").value="" ;
}
</script>
</head>
<body>
<center>
<h2>登入页面</h2>
<form method="post" name="myform">
<p>用户昵称:<input type="text" id="name" name="name"></p>
<p>密 码:<input type="password" id="pwd" name="pwd"></p>
<p><input type="button" value="OK" onclick="return chk()"> <input type="reset" value="reset"></p>
</form>
<a href="register.php">注册</a>
</center>
</body>
indexsend.php页面:
<?php
session_start() ;
error_reporting(E_ALL & ~E_NOTICE);
header("Content-type:text/html ; chareset:gb2312") ;
$name=$_POST["name"] ;
$pwd=$_POST["pwd"] ;
$name=iconv("utf-8" , "gb2312//IGNORE" , $name) ;echo $_REQUEST["name"]."#####" ;
echo $_POST["pwd"]."@@@@@@" ;include_once("conn.php") ;
$result=mysql_query("select * from chatuser where name='$name' and pwd='$pwd'") ;//var_dump("select * from chatuser where name='".$name."' and pwd='".$pwd."'") ;$num=mysql_num_rows($result) ;
if(($num)>0){
while($arr=mysql_fetch_object($result)){
$id=$arr->id ;
$name=$arr->name ;
$_SESSION["id"]=$id ;
$_SESSION["name"]=$name ;
}
echo "1" ;
}
else{
echo "0" ;
}
mysql_close() ;
?>
开始调试的时候,运行是成功的。但是我把php.ini文件改了之后,就出现了问题,然后我又把配置文件更改回来了,再调试的时候,就出现了问题——值传不过来。我当时改的是session属性,因为在打开phpMyAdmin的时候,出现了问题。
求各位给予帮助。
<head>
<title>Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
function chk(){
if(validate_form()==false){
return ;
}
validate() ;
} function validate_form(){
if(document.myform.name.value==""){
alert("昵称不能为空!") ;
return false ;
}
if(document.myform.pwd.value==""){
alert("密码不能为空!") ;
return false ;
}
}
var xmlHttp ;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP") ;
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest() ;
}
}
function validate(){
createXMLHttpRequest() ;
var name=document.getElementById("name").value ;
var pwd=document.getElementById("pwd").value ;
var str="name="+name+"&pwd="+pwd ;
xmlHttp.open("POST" , "indexsend.php" , true) ;
xmlHttp.onreadystatechange=callback ;
xmlHttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded") ;
xmlHttp.send(str) ;
}
function callback(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var str=xmlHttp.responseText ;
if(str=="1"){
alert("该用户存在,页面将会转向首页") ;
window.location="chating.php" ;
}
else{
alert("用户不存在或密码错误,请确认后再输入") ;
clear() ;
}
}
}
}
function clear(){
document.getElementById("name").value="" ;
document.getElementById("pwd").value="" ;
}
</script>
</head>
<body>
<center>
<h2>登入页面</h2>
<form method="post" name="myform">
<p>用户昵称:<input type="text" id="name" name="name"></p>
<p>密 码:<input type="password" id="pwd" name="pwd"></p>
<p><input type="button" value="OK" onclick="return chk()"> <input type="reset" value="reset"></p>
</form>
<a href="register.php">注册</a>
</center>
</body>
indexsend.php页面:
<?php
session_start() ;
error_reporting(E_ALL & ~E_NOTICE);
header("Content-type:text/html ; chareset:gb2312") ;
$name=$_POST["name"] ;
$pwd=$_POST["pwd"] ;
$name=iconv("utf-8" , "gb2312//IGNORE" , $name) ;echo $_REQUEST["name"]."#####" ;
echo $_POST["pwd"]."@@@@@@" ;include_once("conn.php") ;
$result=mysql_query("select * from chatuser where name='$name' and pwd='$pwd'") ;//var_dump("select * from chatuser where name='".$name."' and pwd='".$pwd."'") ;$num=mysql_num_rows($result) ;
if(($num)>0){
while($arr=mysql_fetch_object($result)){
$id=$arr->id ;
$name=$arr->name ;
$_SESSION["id"]=$id ;
$_SESSION["name"]=$name ;
}
echo "1" ;
}
else{
echo "0" ;
}
mysql_close() ;
?>
开始调试的时候,运行是成功的。但是我把php.ini文件改了之后,就出现了问题,然后我又把配置文件更改回来了,再调试的时候,就出现了问题——值传不过来。我当时改的是session属性,因为在打开phpMyAdmin的时候,出现了问题。
求各位给予帮助。
但是我把php.ini文件改了之后,就出现了问题
出现了什么问题?
然后我又把配置文件更改回来了,再调试的时候,就出现了问题——值传不过来。
是SESSION的值不能传递吗?
Microsoft.XMLHTTP 会缓存传输时接受到的数据,而你的代码中并没有禁止缓存的设置
清空浏览器的缓存后再行测试调试时最好 alert(xmlHttp.responseText); 看看服务器端都返回了什么
我之前的调试都清除了缓存的,浏览器“工具”——“internet选项”——“清除历史记录”,就这样算清除缓存的,对吗???我之前的一个php+Ajax代码,也是这样的问题,我过了两个星期,代码不需要什么更改,就运行成功了。
纳闷,这是为什么??????
求高手推荐一个php编辑器的软件,以方便代码的调试。在此谢谢各位了。