Javascript AngularJS文章第404页未找到错误
我正在尝试从我的web应用程序联系人页面发送电子邮件 我在前端使用AngularJS,在服务器端使用node.js 我正在本地机器上运行这个 我相信我为controller http.post方法使用了错误的url,但我不确定该使用什么。运行web应用程序时的url为: 我是想在url中添加核心%20Gaming%20JS/index.html,还是它的一些变体?我尝试将其包含在url中,但没有解决问题 客户端错误:POST 404(未找到) 我的控制器代码:Javascript AngularJS文章第404页未找到错误,javascript,angularjs,node.js,express,Javascript,Angularjs,Node.js,Express,我正在尝试从我的web应用程序联系人页面发送电子邮件 我在前端使用AngularJS,在服务器端使用node.js 我正在本地机器上运行这个 我相信我为controller http.post方法使用了错误的url,但我不确定该使用什么。运行web应用程序时的url为: 我是想在url中添加核心%20Gaming%20JS/index.html,还是它的一些变体?我尝试将其包含在url中,但没有解决问题 客户端错误:POST 404(未找到) 我的控制器代码: mainApp.controlle
mainApp.controller('controller_contact', ['$scope', 'MyService', '$http', function ($scope, MyService, $http) {
$scope.formInput = {
name: "",
email: "",
message: ""
};
$scope.submitForm = function (isValid) {
$scope.formInput = {
name: $scope.formInput.name,
email: $scope.formInput.email,
message: $scope.formInput.message
};
if (isValid) {
console.log($scope.formInput);
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http.post('/contact', $scope.formInput)
.success(function (data) {
console.log("Success!" + data);
})
.error(function (data) {
console.log('Error: ' + data);
});
console.log('Message sent successfully');
}
}
}])
这是我的服务器(Node.js):
这是我的HTML:
<div class="container" ng-controller="controller_contact">
<h2>Contact Us</h2>
<form class="contactForm" name="form_contact" ng-controller="controller_contact"
ng-submit="submitForm(form_contact.$valid)" novalidate>
<div class="form-group">
<label for="contact_form_name">Name</label>
<input id="contact_form_name" type="text" name="name" ng-model="formInput.name" placeholder="Full name"
required>
</div>
<div class="form-group">
<label for="contact_form_email">Email</label>
<input id="contact_form_email" type="email" name="email" ng-model="formInput.email"
placeholder="Email address"
required>
</div>
<div class="form-group">
<label for="contact_form_message">How can we help you?</label>
<textarea id="contact_form_message" name="message" rows="4" ng-model="formInput.message"
placeholder="Type message here." required></textarea>
</div>
<input type="submit" value="Send" ng-disabled="form_contact.$invalid"/>
</form>
<br>
</div>
联系我们
名称
电子邮件
我们能为您做些什么?
<div class="container" ng-controller="controller_contact">
<h2>Contact Us</h2>
<form class="contactForm" name="form_contact" ng-controller="controller_contact"
ng-submit="submitForm(form_contact.$valid)" novalidate>
<div class="form-group">
<label for="contact_form_name">Name</label>
<input id="contact_form_name" type="text" name="name" ng-model="formInput.name" placeholder="Full name"
required>
</div>
<div class="form-group">
<label for="contact_form_email">Email</label>
<input id="contact_form_email" type="email" name="email" ng-model="formInput.email"
placeholder="Email address"
required>
</div>
<div class="form-group">
<label for="contact_form_message">How can we help you?</label>
<textarea id="contact_form_message" name="message" rows="4" ng-model="formInput.message"
placeholder="Type message here." required></textarea>
</div>
<input type="submit" value="Send" ng-disabled="form_contact.$invalid"/>
</form>
<br>
</div>