[英]AngularJS + PHP contact form, POST 405 (Not Allowed)
每當我嘗試通過聯系表單發送消息時,控制台中都會顯示POST 405(不允許)。
App.js
$scope.submitData = function() {
$http({
url: 'handle.php',
method: 'POST',
data: {"name": $scope.name,"email": $scope.email,"message": $scope.message},
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
})
.success(function() {
window.alert("Success");
})
.error(function() {
window.alert("Failure");
})
}
Handle.php
$json = file_get_contents("php://input");
$data = json_decode($json, true);
$to = "myemail@gmail.com";
$name = $data['name'];
$email = $data['email'];
$message = $data['message'];
//to, subject, message, headers, parameters.
mail($to, $name, $email, $message);
?>
Contact.html
<form action="" method="post" ng-submit="submitData()" ng-controller="contactController">
<p>name:</p>
<input name="name" type="text" ng-model="name">
<p>email:</p>
<input name="email" type="text" ng-model="email">
<p>message:</p>
<textarea name="message" type="text" cols="40" rows="5" ng-model="message"></textarea>
<p><div id="html_element"></div><p>
<input type="submit" id="submit" value="Submit"/>
</form>
我在樹莓派上運行Nginx Web服務器。
handle.php是否正確?
我認為此錯誤意味着服務器上未配置某些內容? 我需要配置什么?
我將不勝感激任何幫助。
我認為您應該安裝一個插件來對其他服務器進行ajax調用。 嘗試下載此文件,可能會有所幫助: https : //chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
安裝后,單擊插件,添加並添加URL: https : //developer.chrome.com/extensions/match_patterns ,然后重試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.