我有一种情况,我想同时将表单数据发布到2个不同的位置。我无法控制位置,它们是跨域的。 我在这里发现了一篇以前的帖子,使用了一个iframe,现在我找不到,我已经注册了。它每次提交给第一个,但第二个只提交25%的时间。我需要它在所有主要浏览器中更可靠地工作。尝试使用Ajax,但无法让它在IE中跨域尝试在这个论坛中提出的许多解决方案。 谢谢。 埃德将表单提交到2个不同的网站第二次通过javascript
<form name="myForm" method="post" action="http://www.firstwebsite.com" onsubmit="return submit2nd()" >
<input type="email" name="email" value='' />
<input type="submit" name="submit" />
</form>
<script>
function submit2nd(){
var x=document.forms["myForm"]["email"].value;
var iframe = document.createElement("iframe");
var uniqueString = "asderwegthyuq123";
document.body.appendChild(iframe);
iframe.style.display = "none";
iframe.contentWindow.name = uniqueString;
var form = document.createElement("form");
form.target = uniqueString;
form.action = "http://www.secondwebsite.com";
form.method = "POST";
var input = document.createElement("input");
input.type = "hidden";
input.name = "email";
input.value = x;
form.appendChild(input);
document.body.appendChild(form);
form.submit();
return true;
}
</script>
感谢您的回应rationalboss, 不确定如何实现您的解决方案,但我仍然需要去www.firstwebsite.com提交后,所以不会创建2个不可靠的提交表单,而不仅仅是一? Ajax将无法正常工作,因为它需要在IE中工作,跨域,并且我无法修改目标。我花了4天时间尝试了许多Ajax解决方案,其中没有一个能够在IE中使用。他们在Chrome和FF中工作正常。 – 2013-03-13 06:56:02
[JQuery适用于Internet Explorer。](http://jquery.com/browser-support/)。提交后,您可以通过使用'' – rationalboss 2013-03-13 07:53:06