AngularJs $http error bei Ajax Call

messmar

Erfahrenes Mitglied
Hallo Folks,

bei einem Angular Ajax Call bekomme ich immer wieder einen Fehler der sich auf den
Response bezieht:

Firefox console: Error: data.errors is undefined
Chrome Console: TypeError: Cannot read property 'name' of undefined

JavaScript Code:
Javascript:
var formApp = angular.module('formApp', [] );

function formController($scope, $http){
  $scope.formData = {};
  console.log($scope.formData);
  $scope.processForm = function(){
  $http({
  method  : 'post',
  url  : 'api/checkUser.jsp',
  data  : $.param( $scope.formData ),
  headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
  })
  .success(function(data){
  console.log(data);
  if(!data.success){
  alert('ERROR');
  $scope.errorName = data.errors.name;
  $scope.errorSuperhero = data.errors.superherosAlias;
  } else {
  $scope.message = data.message;
  }
  });
  };
}

HTML CODE:

HTML:
<body ng-app="formApp" ng-controller="formController">
   

  <div class="container">
  <div class="col-md-6 col-md-offset-3">

  <div class="page-header">
  <h1>
  <span class="glyphicon glyphicon-tower"></span>
  Submitting Forms with Angular
  </h1>
  </div>

  <div id="messages" ng-show="message">{{ message }}</div>

  <form ng-submit="processForm()">
  <div id="name-group" class="form-group" ng-class="{'has-error' : errorName}">
  <label>Name</label>
  <input type="text" name="name" class="form-control" placeholder="Bruce Wayne" ng-model="formData.name">
  <span class="help-block" ng-show="errorName">{{ errorName }}</span>
  </div>

  <div id="superhero-group" class="form-group" ng-class="{'has-error':errorSuperhero}">
  <label>Superhero Alias</label>
  <input type="text" name="superheroAlias" class="form-control" placeholder="Caped Crusader" ng-model="formData.superheroAlias">
  <span class="help-block" ng-show="errorSuperhero">{{ errorSuperhero }}</span>
  </div>

  <button type="submit" class="btn btn-success btn-lg btn-block">
  <span class="glyphicon glyphicon-flash"></span> Submit!
  </button>
  </form>
   
  {{ formData }}
   
  </div>
  </div>
      
  </body>

Der Fehler ist in der folgenden Zeile:

Javascript:
..
$scope.errorName = data.errors.name;
...

Ich komme leider nicht weiter und googeln hat nicht viel gebracht.. - zumindest bis jetzt -

Tipp oder Idee?

Danke & Grüße
Messmar