2017-02-20 11 views
0

投稿しているようではない角度コードがあります。 正直言って、firefoxは投稿パラメータを示していますが、私のサーバでprint_r($ _ POST)を実行し、firefoxを介して応答を見ると空の配列が表示されます。

以下はコードの一部です。

$http({ 
      method: 'POST', 
      data : { slotid : slotid }, 
      url: "https://mydomain.abc/Api/reserve_slot/" + slotid + "/" + $scope.docid, 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
     }).then(function successCallback(response) {  
      $scope.r = response.data.list; 
      console.log($scope.r); 
      if($scope.r.status == 1){ 

       $scope.hide(); 
       $state.go('booking', { slotid: slotid }); 
      } 

     }); 

URLが呼び出されています。私が変数/値をURLに渡すために付加すると、(明らかに)うまく動作するからです。 私はちょうどポストが働いていない理由はありません。

私はテストしました。data : { slotid : slotid },にはslotidの値があります。

アイデア?

-----編集 以下は完全なコントローラコードです。

.controller('doctorCtrl', ['$scope', '$stateParams', '$http', '$ionicLoading', '$state', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller 
// You can include any angular dependencies as parameters for this function 
// TIP: Access Route Parameters for your page via $stateParams.parameterName 
function ($scope, $stateParams, $http, $ionicLoading, $state) { 
    $scope.docid = $stateParams.docid; 
    $scope.show = function() { 
     $ionicLoading.show({ 
      content: 'Loading', 
      showBackdrop: false, 
      animation: 'fade-in', 
     }).then(function(){ 
      console.log("The loading indicator is now displayed"); 
     }); 
     }; 
    $scope.hide = function(){ 
     $ionicLoading.hide().then(function(){ 
      console.log("The loading indicator is now hidden"); 
     }); 
     }; 
    $scope.show(); 
    $http({ 
     method: 'POST', 
     url: "https://mydomain.abc/Api/docinfo", 
     data : { docid : $scope.docid }, 
     headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
    }).then(function successCallback(response) {  
     $scope.docinfo = response.data.info; 
     console.log($scope.docinfo); 
     $scope.loadslots($scope.docid,0); 
     //return response.data.list; 
    }); 
    $scope.loadslots = function(docid,dinaya){ 
     $http({ 
      method: 'GET', 
      url: "https://mydomain.abc/Api/get_slots/" + docid + "/" + dinaya, 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
     }).then(function successCallback(response) {  
      $scope.slots = response.data.list; 
      console.log($scope.slots); 
      $scope.hide(); 
     }); 
    } 
    $scope.showslot = function(slotid){ 
     $scope.show(); 
     //data: $.param({slotid: slotid}) 

     $http({ 
      method: 'POST', 
      //data : { slotid : slotid }, 
      //data: $.param({slotid: slotid}), 
      url: "https://mydomain.abc/Api/reserve_slot/" + slotid + "/" + $scope.docid, 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
     }).then(function successCallback(response) {  
      $scope.r = response.data.list; 
      console.log($scope.r); 
      if($scope.r.status == 1){ 
       $scope.hide(); 
       $state.go('booking', { slotid: slotid, docid: $scope.docid }); 
      } 

     }); 
    } 

}]) 

イオン1アプリを構築しようとしています.Jqueryを追加していません。

Codeigniterコントローラを追加しています。

public function reserve_slot(){ 
     /* 
     print_r($_POST); //shows me an empty array 
     $slot = $this->input->post('slotid); //no data here 
     $doc = $this->input->post('doc'); //no data here 
     */ 
     $slot = $this->uri->segment(3); 
     $doc = $this->uri->segment(4); 
     $this->load->model('Doctor'); 
     $this->Doctor->reserve_slot($slot); 
     $list['status'] = 1; 
     $data['list']= $list; 
     header("Access-Control-Allow-Origin: *"); 
     header("Access-Control-Allow-Methods: PUT, GET, POST"); 
     header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); 
     header('Content-Type: application/json'); 
     echo json_encode($data); 
    } 
+1

は、私はあなたが、あなたのデータのための変換関数を[http://stackoverflow.com/questions/24710503/how-do-i-post-urlencoded-form-data-with-http-をチェックアウトする必要があると思いますin-angularjs](http://stackoverflow.com/questions/24710503/how-do-i-post-urlencoded-form-data-with-http-in-angularjs) –

+0

こんにちは、$ .paramsを追加しようとしました。しかし、私は以下のエラーが発生しています。 ReferenceError:$は定義されていません。私はイオンでこれを試みています。私が注射する必要のある種の依存関係はありますか? –

+0

$ jQueryがプロジェクトに含まれていない場合は、[このコメント](http://stackoverflow.com/a/24964658/6301009)のように独自の変換関数を作成してみてください。 –

答えて

0

は角が判明したクエリで$ .PARAMのための同じようなことがあります。

以下のコードは転記されました。

$scope.showslot = function(slotid){ 
     $scope.show(); 
     //data: $.param({slotid: slotid}) 
     var pdata = { slotid : slotid , docid : $scope.docid}; 
     $http({ 
      method: 'POST', 
      //data : { slotid : slotid }, 
      data: $httpParamSerializerJQLike(pdata), 
      url: "https://mydomain.abc/Api/reserve_slot/" + slotid + "/" + $scope.docid, 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
     }).then(function successCallback(response) {  
      $scope.r = response.data.list; 
      console.log($scope.r); 
      if($scope.r.status == 1){ 
       $scope.hide(); 
       $state.go('booking', { slotid: slotid, docid: $scope.docid }); 
      } 

     }); 
    } 
関連する問題