【发布时间】:2016-03-21 12:12:45
【问题描述】:
我有一个表单,当我提交它时,会显示另一个表单,其中包含其他数据的单选按钮。我选择一个并提交。我希望数据显示在另一个页面中,但它没有显示我所做的任何内容。
所以有 /form 路由,我想在上次提交后用我的数据重定向到 /confirmation 路由。
Bellow 是我在 angularjs 中的 formController
.controller('formController', ['$scope', '$http', '$location', function($scope, $http, $location) {
$scope.pageClass = 'form';
$scope.firstName = '';
$scope.lastName = '';
$scope.email = '';
$scope.departure = '';
$scope.destination = '';
$scope.submitFirstForm = function() {
$http.post('/form', {
firstName: $scope.firstName,
lastName: $scope.lastName,
email: $scope.email,
departure: $scope.departure,
destination: $scope.destination,
}).then(function(res) {
$scope.response = res.data;
});
}
$scope.submitConfirmationForm = function(flight){
$http.post('/confirmation', {
departure: $scope.departure,
destination: $scope.destination
}).then(function(res) {
$scope.otherResponse = res.data;
$location.path("/confirmation");
});
};
}]);
Bellow 是我的特快专递功能,仅适用于 /CONFIRMATION 路线
app.post("/confirmation",function(req,res)
{
var departure=req.body.departure;
var destination=req.body.destination;
otherResponse = {
"confirmation": [{
"departure": departure,
"destination": destination,
"msg": "MSG OK",
}]
};
res.json(otherResponse);
});
最后,在我的 Confirmation.html 中查看我的 json otherReponse 发生了什么
<pre>
{{otherResponse | json}}
</pre>
【问题讨论】:
标签: javascript angularjs forms express