I am trying to do a POST request to a login api through angular js .
<form method="post" ng-submit="doLogin()">
<div class="list">
<label class="item item-input">
<span class="input-label">Username</span>
<input type="text" ng-model="loginData.user_mail">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input type="password" ng-model="loginData.password">
</label>
<label class="item">
<button class="button button-block button-positive" type="submit" >{{loginTxt}}</button>
</label>
</div>
</form>
Controller.js
$scope.doLogin=function(){
$http({
method : 'POST',
url : 'http://examplemns.com/customer/api/v1/login/login',
data : $scope.loginData, //forms user object
timeout:20000
})
.success(function(response){
alert(JSON.stringify(response));
})
.error(function(err){
console.log(JSON.stringify(err));
alert("Network error");
});
}
But i will get invalid username response even if the username and password is correct.
I checked the api through postman plugin its working fine,but when comes with angular i will get invalid.
Here is the sample input
user_mail:[email protected]
password:123456
When try this input with postman plugin i will get the correct response
{
"status": 1,
"message": "Done",
"data": {
"name": "A.V.M TOURIST HOME",
"username": "[email protected]",
"id": "37",
"key": "cos4ok88woo0kcw40cog0s4gg4skogscso8848ok"
}
}
but when trying through the angularjs post i with the same input i will get this response
{"status":0,"message":"Invalid username"}
Please help me:(
UPDATE
I need to transform my data to application/x-www-form-urlencoded rather than json (from comments) for that i am used this way.
var data= {user_mail:$scope.loginData.user_mail,password:$scope.loginData.password};
$http({
method : 'POST',
url : 'http://examplemns.com/customer/api/v1/login/login',
data : data,
timeout:20000
})
.success(function(response){
alert(JSON.stringify(response));
})
.error(function(err){
console.log(JSON.stringify(err));
alert("Network error");
});
But again i will get the same
Screenshot of request and response from the postman
