我有一个当前发布到一个位置的表单,但是我希望同时将数据发送到另一个位置但更改 ID,例如当前电子邮件的名称属性是 id="ApplicationAppEmail"
但我希望在第二个表单上提交名称属性为 id="Email"
因为第二个服务器接受帖子的方式不同。
我在这里阅读了很多主题,但找不到执行此操作的确切方法。
最佳答案
您可以做两件事。 当您通过 ajax 发布时,您可以:
<script>
var getEmail;
$('#form').on('submit', function(){
getEmail = $("#emailId").val();
$.ajax({
type: 'POST',
url: 'https://test.com//Action/SavePageOne',
crossDomain: true,
data: { ApplicationAppEmail : getEmail },
success: function(responseData, textStatus, jqXHR) {
var value = responseData.someKey;
},
error: function (responseData, textStatus, errorThrown) {
alert('POST failed.');
}
}).then(function(){
$.ajax({
type: 'POST',
url: 'https://test.com//Action/SavePageOne',
crossDomain: true,
data: { email: getEmail },
success: function(responseData, textStatus, jqXHR) {
var value = responseData.someKey;
},
error: function (responseData, textStatus, errorThrown) {
alert('POST failed.');
}
})
})
return false
})
</script>
或者在您支持 SavePageOne 或 SavePageTwo 的情况下,您可以获得 #emailId 并将其转换到那里。
关于javascript - 将表单数据提交到 2 个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31558977/