I'm trying to communicate with server using following code.
$scope.Save = function () {
$scope.loading = true;
if ($scope.roleSetupModel.RoleID === "") {
// Save
//$scope.loading = true;
$http.post('/SecurityModule/RoleSetup/AddRole', JSON.stringify($scope.roleSetupModel))
.success(function (response) {
$scope.loading = false;
$('#addModal').modal('hide');
$scope.BindDataToGrid();
alert("Success");
toastr.success(response.Message);
})
.error(function (response) {
$scope.loading = false;
alert("Fail");
toastr.error(response.Message);
});
}
else {
$http.post('/SecurityModule/RoleSetup/EditRole',
JSON.stringify(convArrToObj($scope.roleSetupModel)))
.success(function (response) {
$('#addModal').modal('hide');
$scope.loading = false;
toastr.success(response.Message);
$scope.BindDataToGrid();
})
.error(function (data) {
$scope.loading = false;
toastr.error(response.Message);
});
}
}
But I'm getting wired behavior. The link is being hit everytime, I put a debugger there, but even before completing the request my page getting kind of refreshed making my model empty with out entering the success or error call back. I know a little about the promise object but couldn't make sense. What I'm doing wrong here?
Save()get called from? Show form html basics. Sounds like form is submitting through default process and page is reloading