How to catch (and display on the client) server-side OData business validation errors in JayData using AngularJs

StackOverflow https://stackoverflow.com/questions/19550010

  •  01-07-2022
  •  | 
  •  

문제

If I am using code such as this (from: http://jaydata.org/blog/jaydata-and-angularjs-continued):

$scope.saveChanges = function () {

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

};

How do I catch any server-side business validation errors that the server may return?

도움이 되었습니까?

해결책

This works:

$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();
    });
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top