我试图通过AJAX提交一个google doc表单,但它不工作。它一直试图将表单发送到我作为GET的页面,而不是我尝试的Google表单POST url请求。AJAX表单发送GET&发送表单到当前页面而不是POST jquery
我的形式看起来像
<form id="ss-form" target="_self" onsubmit="" action="">
.....
<input type="submit" name="submit" value="Submit" id="ss-submit" class="jfk-button jfk-button-action ">
</form>
和我的JS是这样的:
<script>
$('#ss-form').submit(function(e) {
e.preventDefault();
$.ajax({
url: "https://docs.google.com/a/example.com/forms/d/e/1FAI324B_-XUt0dQ-0AmlfwdfUu5dbEefwjVNud_hNlOKQ/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>
但这只是重新加载我的网页像example.com?entry.1850833=test,它是作为一个GET请求。
任何想法为什么会发生这种情况?我如何通过AJAX代码发送它,并停止表单在当前页面刷新为GET?
可能重复的[event.preventDefault()与返回false](http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false) –
我试过这个答案,它没有有所作为@MikeC – user1180888
您是否尝试删除'onsubmit =“”'?你是否把'return false;'添加到你的handler的* end *中?您是否在添加处理程序之前等待DOM准备就绪? –