I have the following controller:
function EditCtrl($scope,$http,$routeParams,$location) {
$scope.master = {};
$scope.actviePath = null;
$http.get("/employeeApp/assets/php/index.php/users/" + $routeParams.id).success(function (data) {
$scope.users = data;
$scope.user = {
name: data.name,
email: data.email,
userName: data.userName,
password: data.password,
role: data.role,
availability: data.availability,
};
});
$scope.update_user = function(user) {
$http.put("/employeeApp/assets/php/index.php/users/"+$routeParams.id, user).success(function(){
$scope.reset();
$scope.activePath = $location.path('/');
});
$scope.reset = function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
};
}
and the following html template:
<div ng-init="$root.title='Add new user'">
<h2>Edit user: </h2>
<form novalidate name="AddNewForm" id="add-new-form" method="post" action="">
<label for="name">Name:</label>
<input type="text" ng-model="user.name" />
<label for="email">Email:</label>
<input type="email" ng-model="user.email" />
<label for="username">Username:</label>
<input type="text" ng-model="user.userName" />
<label for="password">Password:</label>
<input type="password" ng-model="user.password" />
<label for="role">User Role:</label>
<input type="text" ng-model="user.role" />
<label for="availability">Availability: </label>
<input type="text" ng-model="user.availability" />
<!--<input type="hidden" ng-model="user.id" />-->
<br />
<button class="btn btn-primary" id="add-new-btn" ng-click="update_user(user)">Save!</button>
<a href="#/" class="btn">Cancel</a>
</form>
</div>
When I try to edit a user and then save the change the following error appears in console and the form data is not sent to the server:
SyntaxError: Unexpected token S
at Object.parse (native)
at fromJson (angularjs/1.2.6/angular.js:1035:14)
at $HttpProvider.defaults.defaults.transformResponse (angularjs/1.2.6/angular.js:6926:18)
at angularjs/1.2.6/angular.js:6901:12
at Array.forEach (native)
at forEach angularjs/1.2.6/angular.js:302:11)
at transformData angularjs/1.2.6/angular.js:6900:3)
at transformResponse (angularjs/1.2.6/angular.js:7570:17)
at wrappedCallback (angularjs/1.2.6/angular.js:10905:81)
at angularjs/1.2.6/angular.js:10991:26 angular.js:9383
(anonymous function) angular.js:9383
(anonymous function) angular.js:6825
wrappedCallback angular.js:10908
(anonymous function) angular.js:10991
Scope.$eval angular.js:11906
Scope.$digest angular.js:11734
Scope.$apply angular.js:12012
done angular.js:7818
completeRequest angular.js:7991
xhr.onreadystatechange
On server I have a php API made with slim. The link to the server is app/index.php/user/suerId. When I try to output {{user}} it displays data correctly, but I Don't know why I can't sent the data to the server. I am using angularjs 1.2.6. Does anyone knows why this is happening? Thnx in advance!