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

麻烦帮我看看个JAVASCRIPT的提交
我主要要实现提交表单后仍然保留表单的数据,买了本《浅入深学 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>


------解决方案--------------------
在什么浏览器下运行的,代码中创建XMLHttpRequest对象的方法只适用于IE5、6浏览器,兼容各浏览器的写法:

JScript code
function create_obj() {
    var xmlHttp;
    if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
    else if (window.ActiveXObject) xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    return xmlHttp;
}

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

------解决方案--------------------
探讨
我主要要实现提交表单后仍然保留表单的数据