1

I'M USING 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);


  }); }

And when I pick up on my controller it does not return anything

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

Also had problems with the angular version.

Something I'm doing wrong, help please.

IMAGE OF RETURN DATA

ALDEAL1993
  • 21
  • 7

2 Answers2

1

Try this one and check your browser's response for angular

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);  
                });
}
  • I think I have problems retrieving the data in the phalcon controller, data I send from from angular $http ---- I do not know what is the correct way to receive it in my controller ---- I still get back null :/ any other idea – ALDEAL1993 Feb 18 '17 at 15:41
  • Maybe send it as POST request? You can't send post data with get request. – Juri Feb 18 '17 at 15:51
  • I tried with both post and get but I still get null – ALDEAL1993 Feb 18 '17 at 16:04
  • `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(); }` – ALDEAL1993 Feb 18 '17 at 16:05
  • The way I get it on my controller is wrong `$id = $this->request->getPost("Item");` I think it should be otherwise because it does not receive anything – ALDEAL1993 Feb 18 '17 at 16:09
  • I would appreciate your answer, and your help too. – ALDEAL1993 Feb 18 '17 at 16:12
  • i think you should give a try what @Juri mentioned . –  Feb 18 '17 at 17:47
  • Also im not sure but shouldn't you use data, not params? https://docs.angularjs.org/api/ng/service/$http – Juri Feb 18 '17 at 17:54
  • thats a good point , i had an application where the server side was java spring-boot. if i had to take one response i have used data, according to the documentation. when i had to take several parameter from response , i have used data and an array of pram, which worked fine –  Feb 18 '17 at 20:43
  • @ALDEAL1993 have you tried anything so far ? have you made it as POST ? –  Feb 18 '17 at 20:45
  • If I test it as POST, but I do not receive anything in my driver, I do not know what happens, I've been finding out for two days and I can not find an answer – ALDEAL1993 Feb 18 '17 at 20:56
0

I WAS GOING TO RESIGN, BUT FIND SOMETHING IMPORTANT HERE AngularJs $http.post() does not send data IT WAS BY DEFAULT SHIPPING TYPE OF ANGULAR

Content-Type: application/json

WHAT IS USED BY JQUERY IS

Content-Type: x-www-form-urlencoded

FOR THAT I DO NOT GET RESULT IN MY CONTROLLER, I FINALLY GET MY LATEST CODE

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

GOOD AT LEAST SOMETHING I RESOLVED MY PROBLEM WITH THAT. THANK´S AND EXCUSE ME MY EVIL ENGLISH.

Community
  • 1
  • 1
ALDEAL1993
  • 21
  • 7