2016-08-09 28 views
0

努力獲取http:get可以在Ionic應用程序中從API服務器獲取請求,任何人都可以幫助完成代碼。以下是我有:從Angular API中的API服務器拉取JSON數據

<form ng-submit="getOrders()"> 
     <label class="item item-input item-stacked-label"> 
      <span class="input-label">Search Order #</span> 
      <input type="text" name="order number" placeholder="enter order number" ng-model="query"> 
     </label> 
     <input class="button button-block button-positive" type="submit" name="submit" value="Submit">      
    </form> 

    $scope.getOrders= function(){ 
       $http.get('http://example.com/api/booking/orders/'+ $scope.query).success(function(data) { 
        $scope.orders = [ data.data ]; 
        $scope.query = query; 
        console.log(query); 

       }) 
       } 

這裏有幾個HTTP GET的代碼塊我沒有成功嘗試

//$http.get('http://example.com/api/booking/get/orders/').success(function(data) { 
    //$http({ url: 'http://example.com/api/booking/orders/', method: "GET", params: {query} }).success(function(data) { 
    //$http.get('http://example.com/api/booking/get/orders/+ $scope.query').success(function(data) { 
    //$http.get('http://example.com/api/booking/get/orders/121137').success(function(data) { 
    //$http.get('js/121137.json').success(function(data) { 

Search box

而且,這裏是一些工作POST代碼示例一個API可以提供一些額外的線索,用於從API服務器執行成功的GET查詢: https://plnkr.co/edit/w0cyfzGij8SgcsnbXqsj?p=catalogue

回答

0

使用承諾如下

.then(function(success){ 
//handle success 
}) 
.catch(function(error){ 
//handle error 
}) 
0

這是正確的代碼。

$scope.getOrders= function(){ 
       $http.get('http://example.com/api/booking/orders/'+$scope.query).success(function(data) { 
        $scope.orders = data.data; 
        console.log(data); 
        console.log($scope.query); 

       }) 
       } 
+0

不,這不行,我害怕。只是想知道這是否是我的表單/函數的問題 – me9867