2

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 e.g the value of all href appeared in the page.

MahdiY
  • 1,269
  • 21
  • 32
svatsi
  • 51
  • 3

3 Answers3

1

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;
       });
    };
}]);
Nikhil Aggarwal
  • 28,197
  • 4
  • 43
  • 59
1

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

Community
  • 1
  • 1
ibsenv
  • 619
  • 1
  • 5
  • 18
1

If you want to show image then you only need path/url of image from server not image data or HTML.

Shanky Munjal
  • 671
  • 5
  • 18