Struggling to get http:get to pull a request from a API server in an Ionic app, can anyone help with the code. Here is what I have:
努力获得http:从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);
})
}
Here are a few http get code blocks I have tried without success
这里有一些我试过的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) {
Also, here is an example of some working POST code to an API which may provide some extra clues in performing a successful GET query from an API server: https://plnkr.co/edit/w0cyfzGij8SgcsnbXqsj?p=catalogue
此外,这是一个API的一些工作POST代码的示例,它可以提供一些额外的线索,从API服务器执行成功的GET查询:https://plnkr.co/edit/w0cyfzGij8SgcsnbXqsj?p = catalogue
2 个解决方案
#1
0
use promise as follows
使用承诺如下
.then(function(success){
//handle success
})
.catch(function(error){
//handle error
})
#2
0
this is currect code.
这是当前的代码。
$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);
})
}
#1
0
use promise as follows
使用承诺如下
.then(function(success){
//handle success
})
.catch(function(error){
//handle error
})
#2
0
this is currect code.
这是当前的代码。
$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);
})
}