我有一个AngularJS
应用,其中有一个用PHP
编写的邮件脚本。我试图通过angular
$http
服务引用PHP文件,但是当我尝试通过我的联系表单在相应的控制器中使用它时,我一直收到404错误,就像这样:
angular.module('myModule')
.controller('contactUsController', ['$scope', '$http', function ($scope, $http) {
$scope.formData = {};
$scope.submitted = false;
$scope.submit = function(contactform) {
console.log('Form data', $scope.formData);
$scope.submitted = false;
$scope.submitButtonDisabled = true;
if (contactform.$valid) {
$http({
method : 'POST',
url : "app/process.php",
data : $.param($scope.formData),
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function(data){
console.log(data);
if (!data.success) {
// if not successful, bind errors to error variables
$scope.errorName = data.errors.name;
$scope.errorEmail = data.errors.email;
$scope.errorTextarea = data.errors.message;
$scope.submissionMessage = "Sorry. Error sending message. Please try again.";
$scope.submission = true; //shows the error message
} else {
// if successful, bind success message to message
$scope.formData = {}; // form fields are emptied with this line
$scope.submissionMessage = "Thank you! Your message has been sent successfully.";
$scope.submitted = true; //shows the success message
}
});
} else {
}
}
}]);
因此,每次按下发送按钮调用submit()
功能时,浏览器都会这样抱怨:
我一直在寻找答案,但我找不到可以帮助我的答案。
我正在使用npm start
来运行我的应用。我的项目结构如下图所示:
知道可能出现什么问题吗?任何帮助表示赞赏。