我目前正在尝试在AWS S3上托管一个简单的静态网站。我刚刚制作了一个简单的表单,使用http://formspree.io将表单信息通过电子邮件发送给客户端。该表单在本地功能,但从我可以找到的AWS只能处理GET和HEAD请求,所以我一直收到#405; 405不允许的方法'我的ajax帖子出错了。
即使我在AWS S3上托管,有没有办法仍然可以使用表单大礼包?如果不是在AWS S3上托管的网站上使用功能表单的最佳方法是什么?
表格代码atm:
<form id="contactform" role="form">
<div class="row">
<input type="hidden" name="_subject" value="Website contact - PT Enquiry" />
<div class="form-group col-lg-4">
<label>Name</label>
<input id="name" type="text" name="name" class="form-control">
</div>
<div class="form-group col-lg-4">
<label>Email Address</label>
<input id="email" type="email" name="_replyto" class="form-control">
</div>
<div class="form-group col-lg-4">
<label>Phone Number</label>
<input id="phone" type="tel" name="phone" class="form-control">
</div>
<input type="text" name="_gotcha" style="display:none" />
<div class="clearfix"></div>
<div class="form-group col-lg-12">
<label>Message</label>
<textarea id="message" name="message" class="form-control" rows="6"></textarea>
</div>
<div class="form-group col-lg-12">
<button id="submitForm" class="btn btn-default">Submit</button>
</div>
</div>
</form>
Ajax脚本:
$("#submitForm").on("click", function() {
if ($.trim($("#email").val()) === "" || $.trim($("#name").val()) === "" || $.trim($("#message").val()) === "") {
swal({ title: "Missing Information", text: "Please fill in each field before submiting.", type: "error", confirmButtonText: "Back" });
return false;
}
else{
message = $("#contactform").serializeArray();
var o = {};
var submitTime = new Date();
$.each(message, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
$.ajax({
url: "http://formspree.io/example@gmail.com",
data: {o,submitTime},
header{
}
});
swal({ title: "Success", text: "Thank you for your enquiry", type:"success", confirmButtonText: "Close" });
document.getElementById('contactform').reset();
return false;
}
});
答案 0 :(得分:0)
Ajax请求正在发布到formspree.io而不是S3,所以这不是问题。