[英]Getting empty response from http get request
I develop a web application with MEAN stack. 我开发了一个带有MEAN堆栈的Web应用程序。 Nodejs is use to create the server and to connect Mongodb.
Nodejs用于创建服务器和连接Mongodb。 I need to show json data in the front-end from this url " http://www.booking.com/autocomplete?lang=en-us&aid=304142&term=tha " then add it in mongodb.
我需要在这个URL“ http://www.booking.com/autocomplete?lang=en-us&aid=304142&term=tha ”中显示前端的json数据,然后将其添加到mongodb中。 So i have been using http service of angularjs but getting an empty response while browser is showing it perfectly fine.
所以我一直在使用angularjs的http服务,但是当浏览器显示它完全没问题时获得空响应。 I have tried adding headers and every user-agent.
我尝试过添加标头和每个用户代理。 I have tried in different browsers(Chrome , firefox).
我尝试过不同的浏览器(Chrome,firefox)。 Even python gets non-empty json.
即使是python也会得到非空的json。 Its not working only in angularjs.
它不仅仅适用于angularjs。 Here is the code-
这是代码 -
var app = angular.module('scrapApp', ['ngRoute']);
app.controller('httpCtrl', ['$scope', '$http',function($scope, $http) {
$scope.search = function(){
$http({
method : 'GET',
url : "http://www.booking.com/autocomplete?lang=en-us&aid=304142&term=tha"
}).then(function mySucces(response) {
$scope.data = response.data.city;
}, function myError(response) {
$scope.data = response;
});
};
}]);
Can you guys help me to figure out the problem? 你能帮我解决一下这个问题吗?
Try This: 尝试这个:
var app = angular.module('scrapApp', ['ngRoute']);
app.controller('httpCtrl', ['$scope', '$http',function($scope, $http) {
$scope.data = [];
var ajaxResponse = $http.get('http://www.booking.com/autocomplete?lang=en-us&aid=304142&term=tha');
ajaxResponse.success(function(response, status1, headers, config)
{
$scope.data = response.data.city;
}).error(function(response)
{
$scope.data = response;
});
}]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.