【发布时间】:2016-05-05 05:11:45
【问题描述】:
我目前正在尝试在 AWS S3 上托管一个简单的静态网站。我刚刚制作了一个简单的表单,它使用http://formspree.io 将表单信息通过电子邮件发送给客户。该表单在本地运行,但据我所知,AWS 只能处理 GET 和 HEAD 请求,因此我的 ajax 帖子不断收到“405 Method Not Allowed”错误。
即使我在 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;
}
});
【问题讨论】:
-
POST 请求在哪里?
标签: jquery ajax amazon-web-services amazon-s3