我主要要实现提交表单后仍然保留表单的数据,买了本《浅入深学 php》,里面 395页的代码有个 handle_f, 我照抄,但是我的PHP里没执行,为什么?我这里稍为改了一下,但是PHP 没执行handle_f,如果执行会弹出一个对话框 'hello world'<script language="javascript">var xmlHttp;
xmlHttp=create_obj();function create_obj()
{
  var xmlHttp;
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  return xmlHttp;
}function process()
{
 name=document.getElementById("clinametext").value;
 xmlHttp.open("GET","checkcliname.php?name="+name,true);
 alert("hello world");
 xmlHttp.onreadystatechange=handle_f;
 xmlHttp.send(null);
}function handle_f()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
alert("hello world");
result=xmlHttp.responseText;
c=document.getElementById("message");
c.innerHTML="<b>"+result+"</b>";
}
else
{
alert("执行过程中出现问题,服务器返回:"+xmlHttp.statusText);
}
}
}</script>

解决方案 »

  1.   

    在什么浏览器下运行的,代码中创建XMLHttpRequest对象的方法只适用于IE5、6浏览器,兼容各浏览器的写法:function create_obj() {
        var xmlHttp;
        if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
        else if (window.ActiveXObject) xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        return xmlHttp;
    }http://www.w3school.com.cn/xml/xml_http.asp
      

  2.   

    创建xmlHttp 对象有问题吧。 你那种是ie下的。非ie下的没加进去。改为下面这样试试:
    xmlHttp=window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");  
      

  3.   

    php变量一样可以存储:<?php
    if($_POST){
    $name = $_POST['name'];
    }
    ?>  <form action="test8.php" method="post">
       <input type="text" name="name" value="<?=(empty($name))?"":$name?>"/>
       <input type="submit" name="btn" value="submit"/>
      </form>
      

  4.   

    我的是在linux下的firefox 可能这样出事了