Angularjs使用post和catch响应表单提交,重定向不同视图或在同一视图上显示响应

时间:2014-12-30 06:31:49

标签: angularjs

我是angularjs的新手,我正在尝试使用$ http.post,并希望使用ng-show指令在同一视图或不同视图中显示响应。     控制正在取得成功并显示出分裂并立即消失。请帮帮我。

提前致谢。

var myapp = angular.module('registrationApp', [ 'ngRoute' ]);

// create angular controller
myapp.controller('mainController', function($scope, $http) {

	$scope.regStatus =false;
	// function to submit the form after all validation has
	// occurred
	$scope.submitForm = function() {
		

		user = {    			
			"type" : "admin",
			"emailid" : $scope.user.email,
			
		};
		var res = $http.post('/fosiness-web/services/user/registeruser', user);
       
		res.success(function(data, status, headers, config) {
			alert("Success : " + JSON.stringify({
				data : data	}));
			debugger;
			$scope.mydata = data;
			$scope.regStatus = true;
		});
		res.error(function(data, status, headers, config) {
			alert("failure message: " + JSON.stringify({
				data : data
			}));
		});

	}

});
<div class="container" style="background-color: #E8E8E8;"
		ng-app="registrationApp" ng-controller="mainController">
  ...................
     <div class="alert alert-success" ng-show="regStatus">
				<a href="#" class="close" data-dismiss="alert">&times;</a> Success  <strong ng-                 model="user.message.description">{{mydata}}  {{regStatus}}</strong>
			</div>
  
  
<form id="registrationForm" method="post" method="POST"
					 novalidate
					class="form-horizontal registerForm"
					data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
					data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
					data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
  
                       <div class="form-group">
						<label class="col-sm-3 control-label">Email-Id</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="email"
								ng-model="user.email" data-bv-notempty="true"
								data-bv-notempty-message="The email address is required and cannot be empty"
								data-bv-emailaddress="true"
								data-bv-emailaddress-message="The email address is not a valid" />
						</div>
                      ......................

                   <div class="form-group">
						<div class="col-sm-9 col-sm-offset-3">
							<!-- Do NOT use name="submit" or id="submit" for the Submit button -->
							<button type="submit" class="btn btn-info"
								ng-click="submitForm()">Sign up</button>
							<button type="reset" class="btn btn-warning">Reset</button>
						</div>
					</div>
				</form>
</div>

0 个答案:

没有答案