【问题标题】:angularjs using $http method GET to Phalcon but getting empty params arrayangularjs 使用 $http 方法 GET 到 Phalcon 但获取空参数数组
【发布时间】:2017-07-08 01:50:39
【问题描述】:

我正在使用 Angular 1.6.2 WHIT PHALCON

$scope.selectAction = function(Item){

$http({
  method: 'GET',
  url: 'Mycontroller/new',
  params : {Item : Item},
  headers : {'Accept' : 'application/json'}
}).then(function successCallback(res) {
    // this callback will be called asynchronously
    // when the response is available

    console.log("DATOS : "+res.data.res);

    $scope.lista_premisos = res.data.res;


  }, function errorCallback(data) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.

    console.log(data);


  }); }

当我拿起我的控制器时,它不会返回任何东西

public function newAction()

{

//si es una petición get
if($this->request->isGet() == true) 
{

    $this->view->disable();

    $id = $this->request->getPost("Item");

    $this->response->setJsonContent(array('res' => array($id)));
    $this->response->setStatusCode(200, "OK");
    $this->response->send();
} }

角度版本也有问题。

我做错了,请帮忙。

IMAGE OF RETURN DATA

【问题讨论】:

    标签: angularjs phalcon


    【解决方案1】:

    试试这个并检查浏览器对角度的响应

    function selectAction(Item) {
    
        $http({
            method: 'POST',
            url: 'Mycontroller/new',
            data: Item,
            headers : {'Accept' : 'application/json'}
            })
            .then(
                function successCall(response) {
                    console.log("DATOS :  " + response);
                    $scope.lista_premisos=response;
                },
                function errorCall(response) {
                    console.log(response);  
                    });
    }
    

    【讨论】:

    • 我想我在检索 phalcon 控制器中的数据时遇到问题,我从 angular $http 发送的数据----我不知道在我的控制器中接收它的正确方法是什么 -- -- 我仍然返回 null :/ 任何其他想法
    • 也许将其作为 POST 请求发送?您不能使用 get 请求发送 post 数据。
    • 我尝试了 post 和 get 但我仍然得到 null
    • if($this->request->isPost() == true) { $this->view->disable(); $id = $this->request->getPost("Item"); $payload['result'] = 200; $payload['data']['res'] = $id['Item']; $this->response->setJsonContent($payload); $this->response->setStatusCode(200, "OK"); $this->response->send(); }
    • 我在控制器上获取它的方式是错误的$id = $this->request->getPost("Item"); 我认为应该是其他的,因为它没有收到任何东西
    【解决方案2】:

    我打算辞职,但在这里找到重要的东西AngularJs $http.post() does not send data 它是默认运输类型的 Angular

    Content-Type: application/json
    

    JQUERY 使用的是什么

    Content-Type: x-www-form-urlencoded
    

    因为我在我的控制器中没有得到结果,我终于得到了我的最新代码

    $http({
          method: 'POST',
          url: 'mycontroller/new',
          data: "idtable=" + Item,
          headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        }).then(function successCall(data) {
            console.log(data);
            //$scope.dato = data;
          }, function errorCall(error) {
             console.log(error);
          });
    

    至少我解决了我的问题。谢谢,对不起,我的英语不好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-26
      • 2015-09-07
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 2015-12-15
      • 2011-04-04
      • 2015-08-16
      相关资源
      最近更新 更多