-2
<script type="text/javascript">  
function Add () {

    document.getElementById("newCart.php").submit();
    document.getElementById("PreviousCarts.php").submit();
}
</script>

HTML:

<form name="myform" Id="myform" action="POST" method ="POST"  data-ajax="false">
<div class="main-content-wrapper"> 
<div class="image box-right" style="text-align: center"><img src="pic/shoping cart.jpg" border="0" width="150" height="150" 
                    title="go to a new cart!" onclick="if (validateEmail()) { Add ();} else {return false;}">
<span class="style1"><strong><br>New Shop Cart</strong></span>&nbsp; &nbsp; </div>
<div class="image box-left" style="text-align: center"><img src="pic/page_accept .png" border="0" width="150" height="150" 
                    title="go to a your old shopping bag!" onclick="if (validateEmail()) { Add ();} else {return false;}">
<span class="style1"><strong><br>your Previous shopping carts</strong></span></div>

我们想做 post 或 to form namenewcart或 to form previouscart。我们尝试了这段代码,但它不起作用。你有推荐吗?

4

2 回答 2

1

一旦document.getElementById("newCart.php").submit(); 执行,浏览器就会耗尽以获取下一页。您不能从一个页面发布两个表单(没有 iframe)。

但是,您可以将其中一个放入其中一个表单中并使用/ contenthidden field设置其值,然后发布此表单。PreviousCartsnewCart

于 2012-09-02T11:07:26.863 回答
0

假设其中一个PHP文件只是做一些后台进程和一个显示信息,你可以先通过生成的框架将表单发送到后台进程,稍等片刻,然后提交到主页面:

function Add () {
    var oForm = document.getElementById("myform");

    //create hidden frame:
    var oFrame = document.createElement("iframe");
    oFrame.id = "MyHiddenFrame";
    oFrame.name = "MyHiddenFrame";
    oFrame.style.display = "none";
    document.body.appendChild(oFrame);

    //submit to first page via hidden frame:
    oForm.target = "MyHiddenFrame";
    oForm.action = "PreviousCarts.php";
    oForm.submit();

    //submit to second page:
    oForm.target = "";
    oForm.action = "newCart.php";
    oForm.submit();
}

这不是最佳实践,以防万一由于某种原因您无法执行该服务器端。

于 2012-09-02T11:25:11.820 回答