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>
<td height= "25 "> 密码: </td>
<td height= "25 "> <input name= "password " type= "password " id= "password " size= "20 "> </td>
</tr>
<tr align= "center ">
<td height= "25 " colspan= "2 "> <input type= "button " onClick= "form_submit() " name= "Submit " value= "提交 "> </td>
</tr>
</table>
</form>
</body>
</html>
[解决办法]
form1.submit;
改为 form1.submit();
<input type= "button " onClick= "form_submit() " name= "Submit " value= "提交 "> 改为
<input type= "button " onClick= "form_submit(); " name= "Submit " value= "提交 ">
[解决办法]
我学很长时间,还是有点迷糊,但也具体不知道在什么地方,
不知楼主有没有这种感觉.