Hi All,
I am always having a NULL values when I post the value using Angular JS service to the REST api. When I tried using http post from Railo, I can get the value right. Do you guys know what's I should set from Angular. THANKS.
Here is the Angular controller:
var store1App = angular.module('store1App', [ 'store1AppService']).config(
function($routeProvider,$locationProvider,$httpProvider)
{
$routeProvider.when('/');
$
httpProvider.defaults.headers.post = {'Content-Type': 'application/x-www-form-urlencoded'};
}
);
function Login($scope,Login) {
$scope.error_message = false;
$scope.LoginButton = function () {
var LoginResult = Login.Normal(
{
email:$scope.email,
password:$scope.password,
recaptcha_challenge_field: Recaptcha.get_challenge(),
recaptcha_response_field: Recaptcha.get_response()
},
function(result) {
if (typeof result['success'] === "undefined")
{
if (result['showCaptcha']) {
Recaptcha.create(
$scope.recaptcha_public_key,
"captchaSection",
{
theme: "red",
callback: Recaptcha.focus_response_field
});
$("#captchaSection").css("margin-bottom","18px");
}
$scope.error_message = true;
$scope.errors = result['error'];
}
else
{
$scope.error_message = false;
if (typeof result['url2redirect'] === 'undefined') {
location.reload();
} else {
window.location = result['url2redirect'];
}
}
}
);
};
};
Here is the Angular service:
angular.module('store1AppService',['ngResource' ])
.factory('Login',
function($resource) {
return $resource('rest/jd/user/login.json',
{},
{
Normal:
{
method: 'POST',
email: '@email',
password: '@password',
recaptcha_challenge_field: '@recaptcha_challenge_field',
recaptcha_response_field: '@recaptcha_response_field'
}
}
);
})