日期:2014-05-18  浏览次数:20759 次

ajax 取得服务器返回数据后,再让表单提交出问题
我这个页面只是一个例子而已,我想当ajax   接收到服务器返回数据后,
如果返回的是msg== "0 "   我就让表单提交,否则就不提交,
但是它总是不提交表单,我的目的只是想ajax   返回0的时候让表单submit   ,
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 表单提交测试 </title>
<script   language= "javascript ">
function   ajaxSendServer(url){
if   (window.XMLHttpRequest)  
{  
req   =   new   XMLHttpRequest();  
}
else   if   (window.ActiveXObject)
{  
req   =   new   ActiveXObject( "Microsoft.XMLHTTP ");  
}  
if(req)
{
req.open( "POST ",url,   true);    
req.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded ");                                
req.onreadystatechange   =   complete;      
req.send(null);  
}  
}
  function   complete(){
if(req.readyState   ==   4){
if(req.status   ==   200){  
var   msg=req.responseText;
if(msg== "0 "){
form1.action= "aa.asp "
form1.submit;  
}                      
        }
  }
}
  function   form_submit()   {
    var   f   =   document.form1;
    var   username   =   f.username.value;
    var   password   =   f.password.value;    
    if(username== " "){      
      f.username.focus();
      return   false;
    }
    if(password== " "){      
      f.password.focus();
      return   false;
    }
    var   url   =   "reg.asp?username= "+f.username.value;    
    ajaxSendServer(url);
    //return   true;
  }
</script>
</head>

<body>
<form   name= "form1 "   method= "post ">
        <table   width= "300 "   border= "0 "   cellspacing= "4 "   cellpadding= "0 "   style= "   font-size:12pt; ">
                <tr>
                        <td   width= "74 "   height= "25 "> 用户名: </td>
                        <td   width= "220 "   height= "25 "> <input   name= "username "   type= "text "   id= "username "   size= "20 "> </td>
                </tr>
                <tr>