2017-05-14 197 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

相关问题