我的联系表格正在抛出405(方法不允许错误)。它在一个月前正常运作。我使用ajax将数据发送到php脚本进行处理。我正在使用托管网站的共享主机。我不熟悉.net和Microsoft IIS服务器配置。其他类似的问题建议对web.config文件进行一些更改,但我无法修复此错误。我的HTML代码 -
<!-- Form Name -->
<legend>Fill the form below</legend>
<div class="form-group clearfix">
<label class="col-md-4 control-label">First Name</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input name="firstname" id="firstname" placeholder="First Name" class="form-control" type="text" value="" required>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group clearfix">
<label class="col-md-4 control-label">Last Name</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input name="lastname" id="lastname" placeholder="Last Name" class="form-control" type="text" value="" required>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group clearfix">
<label class="col-md-4 control-label">E-Mail</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input name="email" id="email" type="email" placeholder="E-Mail Address" class="form-control" type="text" value="" required>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group clearfix">
<label class="col-md-4 control-label">Phone </label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
<input name="phone" id="phone" type="text" pattern="^(\d{10})$" data-pattern-error="Enter 10 digit mobile number" placeholder="Enter ten digit phone number" class="form-control" type="text" value="" required>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group clearfix">
<label class="col-md-4 control-label">Proposal Description</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea class="form-control" id="message" type="text" name="message" placeholder="Proposal Description" required></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<!-- Button -->
<div class="form-group clearfix">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" name="submit" id="form-submit" class="btn btn-success btn-lg">Send<span class="glyphicon glyphicon-send"> </button>
</div>
</div>
</fieldset>
</form>
我的Ajax代码 -
function submitForm(){
// Initiate Variables With Form Content
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
var phone = $("#phone").val();
var email = $("#email").val();
var message = $("#message").val();
console.log("Sending form for processing");
$.ajax({
type: "POST",
url: "form-process.php",
data: "firstname=" + firstname + "&lastname=" + lastname + "&phone=" + phone +"&email=" + email + "&message=" + message,
success : function(text){
if (text == "success"){
console.log("Form submitted");
formSuccess();
} else {
formError();
submitMSG(false,text);
}
}
});
}
我的PHP代码 -
$errorMSG = "";
// NAME
if (empty($_POST["firstname"])) {
$errorMSG = "First name is required ";
} else {
$firstname = $_POST['firstname'];
}
if (empty($_POST["lastname"])) {
$errorMSG = "Last name is required ";
} else {
$lastname = $_POST['lastname'];
}
if (empty($_POST["phone"])) {
$errorMSG = "Phone number is required ";
} else {
$phone = $_POST['phone'];
}
// EMAIL
if (empty($_POST["email"])) {
$errorMSG .= "Email is required ";
} else {
$email = $_POST['email'];
}
// MESSAGE
if (empty($_POST["message"])) {
$errorMSG .= "Message is required ";
} else {
$message = $_POST["message"];
}
$body ="From: ".$firstname." ".$lastname."\n Phone: ".$phone."\n E-Mail: ".$email."\n Message: ".$message;
$to = "mail@gmail.com";
$subject = "New message from ".$firstname;
$from = "from@me.com";
// If there are no errors, send the email
$success = mail($to, $subject, $body, $from);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Something went wrong :(";
} else {
echo $errorMSG;
}
}
我无法使用这些http动词 - POST,PUT,DELETE 我通过ajax使用POST方法将数据发送到PHP中的服务器。服务器返回的响应 -
Allow: GET, HEAD, OPTIONS, TRACE
Content-Type: text/html
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Content-Length: 1117
我的web.config文件 -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<tracing>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="WWW Server" areas="Authentication,Cache,CGI,Compression,Filter,Module,RequestNotifications,RequestRouting,Rewrite,Security,StaticFile" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="405" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
</configuration>
以下是来自IIS服务器的失败请求跟踪的输出
Event - MODULE_SET_RESPONSE_ERROR_STATUS
ModuleName StaticFileModule
Notification 128
HttpStatus 405
HttpReason Method Not Allowed
HttpSubStatus 0
ErrorCode 2147942401
ConfigExceptionInfo
Notification EXECUTE_REQUEST_HANDLER
ErrorCode Incorrect function. (0x80070001)
Module Name - StaticFileModule
GET,HEAD,POST,DEBUG,DELETE,PUT - 网站处理程序允许使用这些HTTP方法。