Angularjs 从http get请求获取空响应
我用meanstack开发了一个web应用程序。Nodejs用于创建服务器和连接Mongodb。我需要在前端显示来自此url“”的json数据,然后将其添加到mongodb中。所以我一直在使用angularjs的http服务,但当浏览器显示它非常好时,却得到了一个空响应。 我尝试过添加头和每个用户代理。我尝试过不同的浏览器(Chrome、firefox)。甚至python也会得到非空的json。它不仅在angularjs中有效。这是密码-Angularjs 从http get请求获取空响应,angularjs,json,node.js,Angularjs,Json,Node.js,我用meanstack开发了一个web应用程序。Nodejs用于创建服务器和连接Mongodb。我需要在前端显示来自此url“”的json数据,然后将其添加到mongodb中。所以我一直在使用angularjs的http服务,但当浏览器显示它非常好时,却得到了一个空响应。 我尝试过添加头和每个用户代理。我尝试过不同的浏览器(Chrome、firefox)。甚至python也会得到非空的json。它不仅在angularjs中有效。这是密码- var app = angular.module('sc
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;
});
};
}]);
你们能帮我解决这个问题吗?试试这个:
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;
});
}]);
试试这个:
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;
});
}]);
请求的资源上是否存在“没有‘访问控制允许源代码’标头”。开发人员工具的控制台中出现异常?没有,我认为这是一个响应标头,但不确定。事实上,我对CORS了解不多。请求的资源上是否存在“没有‘访问控制允许源代码’标头”。开发人员工具的控制台中是否出现异常?没有,我认为这是一个响应标头,但不确定。实际上我对CORS了解不多。这也不起作用。顺便说一下,这是AngularJS v1.3.20的语法。我正在使用AngularJSV1.4.8。从这里得到的也不起作用。顺便说一下,这是AngularJS v1.3.20的语法。我正在使用AngularJSV1.4.8。这是从