繁体   English   中英

在Angular 1中从API服务器提取JSON数据

[英]Pulling JSON data from API server in Angular 1

努力获取http:get来从Ionic应用程序中的API服务器提取请求,任何人都可以使用该代码。 这是我所拥有的:

    <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) {

搜索框

另外,这是一些有效的POST代码示例,可以为从API服务器执行成功的GET查询提供一些额外的线索: https : //plnkr.co/edit/w0cyfzGij8SgcsnbXqsj?p=catalogue

使用promise如下

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

这是当前代码。

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

                 })
              }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM