我使用AJAX和Google電子表格通過從表單字段獲取POST數據並通過Google表單將其發送到電子表格,從而爲通訊收集電子郵件數據。我無法讓代碼阻止該頁面重定向到Google的感謝頁面。這是下面的AJAX和表單代碼。停止頁面通過AJAX提交Google表單後重定向
<form class="form-inline" role="form" action="https://docs.google.com/forms/d/1TEPXPqigGuN8sayYjz-sk6H-5wAbPaImsgadM2PBFAk/formResponse" method="POST" id="newsletter-form" target="_self" onsubmit="">
<input type="text" name="entry_291075079" value="" class="form-control" id="Email" dir="auto" placeholder="[email protected]">
</form>
<script>
$("#newsletter-form").submit(function(e) {
e.preventDefault();
$.ajax({
url: "https://docs.google.com/forms/d/1TEPXPqigGuN8sayYjz-sk6H-5wAbPaImsgadM2PBFAk/formResponse",
data: $(this).serialize(),
type: "POST",
dataType: "xml",
success: function(data) {
console.log('Submission successful');
},
error: function(xhr, status, error) {
console.log('Submission failed: ' + error);
}
});
});
</script>
實例化一個新窗口中運行的Ajax,終止新的窗口? – Zze