在表单中提交表单

发布于 2024-11-08 16:09:23 字数 1470 浏览 0 评论 0原文

当我单击“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪化雨蝶 2024-11-15 16:09:23

您不能嵌套表单。您必须更改第一个表单的操作 URL。

You can't nest forms. You will have to change the action url for the first form.

酒儿 2024-11-15 16:09:23

您有一个表单内的表单,外部表单在提交时得到处理。

另外我建议为你的ajax请求使用一个库,我使用jQuery:

$('#secondForm').load('secondForm.html');

更改你的HTML,这样就可以工作:

<form method="POST" action="first.html" id="firstForm">
   <input type="submit" value="Submit First">
</form>

<span id="secondForm"></span>

secondForm.html

<form method="POST" action="second.html" id="secondFormID"> <-- use a different ID
   <input type="submit" value="Submit Second">
</form>

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:

$('#secondForm').load('secondForm.html');

Change you HTML so this would work:

<form method="POST" action="first.html" id="firstForm">
   <input type="submit" value="Submit First">
</form>

<span id="secondForm"></span>

secondForm.html

<form method="POST" action="second.html" id="secondFormID"> <-- use a different ID
   <input type="submit" value="Submit Second">
</form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文