【发布时间】:2017-03-03 03:35:40
【问题描述】:
在我的表单中,我将数据发布到一个外部 url,它是一个 webhook。在用户提交并将数据传递给 webhook 后,我想将用户重定向到确认页面。
我下面的代码有问题。当用户提交表单时,jQuery 确实将用户带到了确认页面,但表单数据不会触发 webhook(不会收集数据)。有人可以帮忙解决我哪里出错了吗?
这是我的代码:
HTML
<form action="https://externalurl.com/webhook" method="POST">
<input id="email" name="email">
<input id="firstname" name="firstname">
<input id="lastname" name="lastname">
<button type="submit">Submit</button>
</form>
jQuery
$('form').submit(function() {
$.ajax({
type: 'POST',
url: $(this).attr('action'),
dataType: 'json',
success: function(json) {
window.location.href = "https://www.mypage.com/confirmation";
}
});
return false;
});
提前致谢
【问题讨论】:
-
您是否发布到与包含表单的域相同的域?如果您违反同源政策 (developer.mozilla.org/en-US/docs/Web/Security/…),您的 POST 将失败
标签: javascript jquery forms post get