I am having an issue with my AngularJS form that is supposed to post data to a Scalatra servlet. Unfortunately, when the form is submitted, I am unable to retrieve any form parameters in my Scalatra servlet.
Here is a snippet of my code:
AngularJS
$scope.createUser = function() {
$http.post('/createUser',{name:$scope.name,email:$scope.email,pwd:$scope.pwd}).
success(function(data, status, headers, config) {
alert("success " + data)
}).
error(function(data, status, headers, config) {
alert("failure =>" +data)
});
}; });
};
HTML form
<form ng-controller="UserController">
<legend>Create User</legend>
<label>Name</label>
<input type="text" id="name" name="name" ng-model="name" placeholder="User Name">
<label>Email</label>
<input type="text" id="email" name="email"
ng-model="email" placeholder="ur email here">
<label>Password</label>
<input type="text" id="pwd" name="pwd"
ng-model="pwd" placeholder="ur own pwd here">
<button ng-click="createUser()" class="btn btn-primary">Register</button>
</form>
Scalatra Servlet
post("/createUser") {
println(params("name"))
}
Upon submitting the form, I encounter the following error:
Error 500 key not found: name (obtained from firebug lite)
If anyone knows what mistake I might be making or if there is another approach I should consider, please do let me know.