简体   繁体   English

从http get请求获取空响应

[英]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.

相关问题 在向Dreamfactory的第一个http请求后获得“ ERR_EMPTY_RESPONSE” - Getting “ERR_EMPTY_RESPONSE” after first http request to Dreamfactory 从$ http调用获取原始请求/响应 - Get raw request / response from $http call Ionic 2:存储来自http GET请求的响应 - Ionic 2: storing the response from an http GET request 从 $http 服务为空的响应中获取 HTTP 状态代码 - Get HTTP status code from a response coming as empty with $http service 使用Karma模拟来自HTTP Post请求的空数组响应 - Simulating an Empty Array Response from an HTTP Post Request using Karma 使用 HTTP GET 请求从 AngularJS 调用 Struts 2 操作类但没有得到任何响应 - Calling Struts 2 action class from AngularJS with HTTP GET request but not getting any response 从$ http promise的响应中获取请求数据 - getting request data from $http promise's response 继续获取HTTP REQUEST的HTTP响应代码“ 1” - keep getting HTTP response code “1” for HTTP REQUEST 在angular-js框架中将HTTP请求发布到本地主机时获取ERR_EMPTY_RESPONSE - Getting ERR_EMPTY_RESPONSE when posting http request to local host in angular-js framework 来自Angular JS的HTTP Get请求收到空回复 - HTTP Get request from Angular JS receives empty reply
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM