在表单中提交表单
当我单击“Submit Second”时,页面将转到first.html。我希望它转到 secondary.html
index.html
<body onload="secondForm();">
<script type="text/javascript">
function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] // activeX versions in IE
if (window.ActiveXObject){ // test support for ActiveXObject in IE
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes[i])
}
catch(e){
// suppress
}
}
}
else if (window.XMLHttpRequest) // mozilla,safari,chrome,opera
return new XMLHttpRequest()
else
return false
}
function secondForm(id) {
var mygetrequest=new ajaxRequest()
mygetrequest.onreadystatechange=function() {
if (mygetrequest.readyState==4) {
if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
document.getElementById("secondForm").innerHTML=mygetrequest.responseText
}
}
}
mygetrequest.open("POST", "secondForm.html, true)
mygetrequest.send(null)
}
</script>
<form method="POST" action="first.html" id="firstForm">
<span id="secondForm"></span>
<input type="submit" value="Submit First">
</form>
secondForm.html
<form method="POST" action="second.html" id="secondForm">
<input type="submit" value="Submit Second">
</form>
When I click "Submit Second," the page goes to first.html. I want it to go to second.html
index.html
<body onload="secondForm();">
<script type="text/javascript">
function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] // activeX versions in IE
if (window.ActiveXObject){ // test support for ActiveXObject in IE
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes[i])
}
catch(e){
// suppress
}
}
}
else if (window.XMLHttpRequest) // mozilla,safari,chrome,opera
return new XMLHttpRequest()
else
return false
}
function secondForm(id) {
var mygetrequest=new ajaxRequest()
mygetrequest.onreadystatechange=function() {
if (mygetrequest.readyState==4) {
if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
document.getElementById("secondForm").innerHTML=mygetrequest.responseText
}
}
}
mygetrequest.open("POST", "secondForm.html, true)
mygetrequest.send(null)
}
</script>
<form method="POST" action="first.html" id="firstForm">
<span id="secondForm"></span>
<input type="submit" value="Submit First">
</form>
secondForm.html
<form method="POST" action="second.html" id="secondForm">
<input type="submit" value="Submit Second">
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能嵌套表单。您必须更改第一个表单的操作 URL。
You can't nest forms. You will have to change the action url for the first form.
您有一个表单内的表单,外部表单在提交时得到处理。
另外我建议为你的ajax请求使用一个库,我使用jQuery:
更改你的HTML,这样就可以工作:
secondForm.html
You have a form within a form, the outer form gets processed on submit.
Also I would suggest using a library for your ajax requests, i use jQuery:
Change you HTML so this would work:
secondForm.html