日期:2014-05-17  浏览次数:20452 次

php与ajax中的问题
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>密&nbsp;&nbsp;&nbsp;码:<input type="password" id="pwd" name="pwd"></p>
<p><input type="button" value="OK" onclick="return chk()">&nbsp;&nbsp;&nbsp;<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文件改了之后,就出现了问题,然后我又把配置文件更改回来了,再调试的时候,就出现了问题——值传不过来。我当时改的是sess