0

如果我使用这样的代码(来自:http: //jaydata.org/blog/jaydata-and-angularjs-continued):

$scope.saveChanges = 函数 () {

$scope.northwind.saveChanges()
.then(function () {
  $scope.selectedProduct = null;
},function() {
  $scope.northwind.stateManager.reset();
});

};

如何捕获服务器可能返回的任何服务器端业务验证错误?

4

1 回答 1

1

这有效:

$scope.saveChanges = function () {
    $scope.ApplicationData.saveChanges()
    .then(function () {
        $scope.selectedToDo = null;
    }, function (error) {
        var xml = error.message,
        xmlDoc = $.parseXML(xml),
        $xml = $(xmlDoc),
        $ValidationResults = $xml.find("ValidationResults");

        angular.forEach($ValidationResults, function (ValidationResult) {
            angular.forEach(ValidationResult.childNodes, function (childNode) {
                alert(childNode.childNodes[0].textContent);
            });
        });

        $scope.ApplicationData.stateManager.reset();
    });
};
于 2013-10-25T02:04:53.210 回答