微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php-如何将数据从angular js发布到zend控制器?

查看页面

<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"));}

我需要从角度形式获取数据并将其传递给zend控制器并执行登录检查并提交形式.有人可以提供逐步说明的帮助吗?

解决方法:

像这样更改您的main.js;

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";
        });
}

在您的PHP文件中访问您的电子邮件和密码,例如;

$email = $_REQUEST['email'];
$password = $_REQUEST['password'];

并将这些凭据发送到您的zend控制器.希望能帮助到你.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐