简体   繁体   中英

Using jquery in angular in returning data from $http.get request

I make an $http.get request to apache server and the response is an HTML page. I would like to use jquery to some data from the HTML page.

The code of my controller is:

app.controller('MainController', ['$scope', '$http', function($scope, $http) {
    $scope.showImages = function() {
        $http.get('http://localhost/images/').success(function(data) {
            $scope.images = data;
        });
    };
}]);

I can see that in $scope.images is stored the html page that return from server but I do not have a clue how to use jquery to extract eg the value of all href appeared in the page.

If you want to extract any information, you can achieve directly from data. Just add data type for the call and use jQuery(data) to access html

app.controller('MainController', ['$scope', '$http', function($scope, $http) {
    $scope.showImages = function() {
        $http.get('http://localhost/images/',
         dataType: "html").success(function(data) {
          // Now use this html Object as normal object and retrieve information 
          var htmlObject = jQuery(data);
          $scope.images = data;
       });
    };
}]);

If I understand you correctly, you need to parse HTML before doing any manipulation. See this SO post.

如果要显示图像,则只需要来自服务器的图像路径/ URL,而无需图像数据或HTML。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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