我正在使用 ajax 将表单发布到我的 localproxy,然后再发布到附属客户以及我的数据库。但是,它要么不使用 ajax 发布,要么出现错误。我在其他网站上使用了这种精确的代码格式,没有问题。
我的ajax代码
$(document).ready(function(){
// ajax code start
$('#form').on('submit', function (e){
e.preventDefault();
$.ajax({
type: "POST",
url: "/localProxy.php",
data: $('#form').serialize(),
success: function (response) {
document.location = '/thank-you';
// do something!
},
error: function () {
alert('There was a problem!'); // handle error
}
});
});
这是我当前的表单标题和提交代码
<form id="form" name="form" >
<input type="submit" name="submit" id="submit" value="Enter" />
默认提交激活绕过 ajax 或出现警报消息。