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.

1
  • DO u want to show image from server? Commented Jun 5, 2015 at 9:47

3 Answers 3

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;
       });
    };
}]);
Sign up to request clarification or add additional context in comments.

3 Comments

I guess that I have to use $http not $http.get in order to add data type.
I don't understand how to retrieve e.g all td tags from that object.
With respect to above code, htmlObject.find("td") will give you the array of all the td tags.
1

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

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.