请教个AJAX问题
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
function nums(){
var n = document.natform.num.value;
var url="index.php?c=nat&a=natid&id="+n+"";
if(n == ''){
document.getElementById('num').style.display='block';
document.getElementById('num').innerHTML='编号不能为空';
document.getElementById('num').style.color='red';
return false;
}else{
xmlHttpRequest = createXmlHttpRequest();
xmlHttpRequest.onreadystatechange = handle;
xmlHttpRequest.open("GET",url,true);
xmlHttpRequest.send(null);
//我的问题就是 在这个else里怎么接收到 handle()的返回值(true false)
}
}
function handle(){
if(xmlHttpRequest.readyState == 4){
var re = xmlHttpRequest.responseText;
if(re){
document.getElementById('num').style.display='block';
document.getElementById('num').innerHTML='编号已存在';
document.getElementById('num').style.color='red';
return false;
}else{
document.getElementById('num').style.display='block';
document.getElementById('num').innerHTML='可以使用';
document.getElementById('num').style.color='green';
return true;
}
}
}
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
function saves(){
if(nums()){
document.natform.action="index.php?c=nat&a=addnatpost";
document.natform.submit();
}
}
var re = xmlHttpRequest.responseText; //这里的re值是多少?alert看看。 //如果没有值,说明是后端接收处理的问题 <br><font color="#e78608">------解决方案--------------------</font><br> ajax 是异步通讯方式,所以你不可能从 num() 得到正确的返回值<br>你所需要的提交动作应在 handle 中完成 <div class="clear"></div>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号