【问题标题】:Angular Js $http.post method unable to access data in Zend FrameworkAngular Js $http.post 方法无法访问 Zend Framework 中的数据
【发布时间】:2015-01-13 06:24:32
【问题描述】:

这是我的 Angular js 函数

 $scope.submitform = function () {
     $http.post('http://localhost:90/vendor/dashboard/accountinfosave/', 
        {'uname': 'vikrant', 'pswd': '111', 'email': 'bhallavikrantvir@gmail.com'}
                ).success(function(data) {
                    alert("success");

                }).error(function(data) { 
                    alert("error occured");

                });


  };

这是我的 Zend 框架控制器函数。

 public function accountinfosaveAction(){
        $data = $this->getRequest()->getPost(); 
       print_r($data);// not working 
       print_r($_POST);// not working  
}

问题是我想访问我使用$http.post函数从Angular Js发送到zend框架的数据(uname,pswd,email)。

如果我使用 $.ajax 函数,它可以正常工作。但是$http.post 不起作用。 请帮帮我。

【问题讨论】:

    标签: javascript php angularjs zend-framework


    【解决方案1】:

    您可以使用它来获取发布请求 $postdata = file_get_contents("php://input");

    【讨论】:

    • 为我工作 print_r($postdata) 给出发布结果。谢谢。
    • 是的,我发现另一篇文章提到角度将数据编码为 json 而不是 php 所期望的。 stackoverflow.com/questions/19254029/…
    【解决方案2】:

    首先,检查帖子网址是否正确,或者在functioncontructor 中使用测试echocontructor

    这样试试,

    var request = $http({
       method: "post",
       url: "http://localhost:90/vendor/dashboard/accountinfosave/",
       data: {
           uname : 'vikrant', 
           pswd  : '111', 
           email : 'bhallavikrantvir@gmail.com'
       }
    });
    
    request.success(
       function( data ) {
          $scope.data = data;
          alert('success');
       }
    );
    

    【讨论】:

    • 我也做过 echo 。只有我无法访问那里的 $_POST 数据才能访问 zend 函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多