2017-05-14 114 views
2

這裏我使用codeigniter和AngularJS ...... 我的代碼有什麼問題?

我想要的是,我想從'輸入文本'中檢索它的數據。

而在AjaxRequest.php

在app.js

$scope.testGetDataSearch = function() 
     { 
      $http({ 
      method: 'GET', 
      url: 'home/naonwelah', 
      data: { 'valSearch': $scope.search_data } 
      }).then(function (success){ 
      console.log(success.data); 
      },function (error){ 
      console.log(error); 
      }); 
     } 

index.html中

<input type="text" ng-model="search_data"> 
<span class="display-ib" ng-click="testGetDataSearch()"></span> 

做 '的console.log()'

時,我只得到空數據

public function naonwelah() 
    { 
     if (isset($_GET['valSearch'])) { 
      $searchValue = $_GET['valSearch']; 
      $result = $this->dbxs7h3j9213m02147ca_model->cariBrow($searchValue); 
      var_dump($result); 
     } 
    } 

回答

2

這很簡單,改變「數據:」到「PARAMS:」,並嘗試這個:)

$scope.testGetDataSearch = function() 
     { 
      $http({ 
      method: 'GET', 
      url: 'home/naonwelah', 
      params: { 'valSearch': $scope.search_data } 
      }).then(function (data){ 
      console.log(data); 
      },function (error){ 
      console.log(error); 
      }); 
     } 
+0

謝謝你的參與:D,這是非常好的:) – Firmansyah

1

如果發生什麼情況你直接打開搜索網址?你有輸出嗎?您是否檢查過ChromeDevTools中的請求?這也可能有助於縮小問題範圍。然而

一個問題可能是,產生的var_dump沒有有效的JSON。

+0

謝謝你的評論,但是當我jQuery的使用$阿賈克斯()我得到的結果,因爲我認爲合適 – Firmansyah

相關問題