PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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控制器.希望能帮助到你.

大佬总结

以上是大佬教程为你收集整理的php-如何将数据从angular js发布到zend控制器?全部内容,希望文章能够帮你解决php-如何将数据从angular js发布到zend控制器?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: