我試圖使用以下代碼與服務器通信。
$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);
});
}
}
但我得到有線行爲。該鏈接每次都會被打到,我在那裏放了一個調試器,但是即使在完成請求之前,我的頁面也會被刷新,從而使我的模型變空,而無需輸入成功或錯誤回調。我對承諾對象有一點了解,但沒有意義。我在這裏做錯了什麼?
哪裏'保存()'也會從叫什麼名字?顯示錶單html基礎。聽起來像表格正在通過默認過程提交,並且頁面正在重新加載 – charlietfl