【发布时间】:2014-06-18 15:21:13
【问题描述】:
我是编码新手,正在尝试使用“联系我们”表单构建网站,因此,我使用 jquery 验证复制了一个演示表单。想如果我能得到这个工作,那么我可以添加一些格式来使它适合我的网站。问题是表单加载正确,但是,当按下“发送联系表单”按钮时,我收到 HTTP 错误 405.0 - Method Not Allowed 错误。我好像搞不懂。
感谢您的任何建议
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#theForm").validate();
});
</script>
</head>
<body>
<h1>Form Validation Using jQuery and PHP | Demo</h1>
<!-- The form that will be parsed by jQuery before submit -->
<div class="layout">
<form id="theform" method="post">
<label for="firstName">Your First Name</label>
<input class="required" name="firstname" type="text" id="firstName">
<label>Your Message</label>
<textarea name="comments" rows="5" style="width:535px"></textarea>
<input class="button" type="submit" value="SEND CONTACT FORM" />
</form>
<?php echo $output; ?>
</div>
<!-- jQuery Form Validation code -->
<script>
// When the browser is ready...
$(function() {
// Setup form validation on the #register-form element
$("#register-form").validate({
// Specify the validation rules
rules: {
name: "required",
gender: "required",
address: "required",
email: {
required: true,
email: true
},
username: "required",
password: {
required: true,
minlength: 5
}
},
// Specify the validation error messages
messages: {
name: "Please enter your name",
},
submitHandler: function(form) {
form.submit();
}
});
});
</script>
</body>
</html>
【问题讨论】:
-
您没有为表单提供
action,这意味着浏览器会将其发送到此表单所在的同一地址——如果那是.htm(l)页面(而不是某种处理发送数据的脚本),一些 Web 服务器被配置为不允许静态 HTML 文件的 POST 请求。
标签: jquery http-status-code-405