how to post data From angular js to zend controller?
angularjs, php, zend-framework2
Solution
Change your main.js like this;
function LoginCtrl($scope, $http) {
$scope.login = {email: "", password: ""};
$scope.login = $.param($scope.login);
$scope.submit = function(){
$http({
method: 'POST',
url: '/login',
data: $scope.login,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).
success(function(response) {
window.location.href = "/login";
}).
error(function(response) {
$scope.codeStatus = response || "Request failed";
});
}
In your php file access your email and password like;
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
and send these credentials to your zend controller. Hope it helps.
Problem
view page: ``` <div ng-controller="LoginCtrl"> <form name="login_form" ng-submit="submit()" > Email: <input type="email" ng-model="login.email" required/><br /> Password: <input type="password" ng-model="login.pass" required/><br /> <input type="submit" /> </form> ``` main.js ``` function LoginCtrl($scope, $http) { $scope.login = {}; $scope.submit = function(){ $http({ method: 'POST', url: '/login', data: $scope.login, headers: {'Content-Type': 'application/x-www-form-urlencoded'} }). success(function(response) { window.location.href = "/login"; }). error(function(response) { $scope.codeStatus = response || "Request failed"; }); } ``` LoginController: ``` if ($request->isPost()) { $data = json_decode(file_get_contents("php://input"));} ``` i need to fetch data from angular form and pass it to zend controller and perform login check and submit form.Could anybody help with step by step explanation?