Getting html content of a URL specified in AngularJS

I use $ http.get ('url') to get the content present in the real url. The html in 'url' is as follows

<html> <head></head> <body> <pre style = "word-wrap: break-word; white-space: pre-wrap;"> <!-- content is present here --> </pre> </body> </html> 

When I create $ http.get for this URL, I get some data and the required content

 GET /TYPE=abvd HTTP 1.1 content required .0.1234.123 Safari /123.12 Referer: //url of the webpage calling this function Accept-Encoding: ............... 

How to get rid of this additional information and get only content? (I know we can just parse the answer, but is there a better way to do this?)

EDIT: The received data response was detected in google chrome, when I run the same script in IE10, I get only “html content” as desired. Why does this difference arise and how can I handle it?

+5
source share
1 answer

$http.get returns HttpPromise , and from it you can get the basic data as follows:

 $http.get('url').then(function(response) { html = response.data; }); 

To get even more useful data, you can expand it like this:

 $http.get('url').then( // success handler function(response) { var data = response.data, status = response.status, header = response.header, config = response.config; }, // error handler function(response) { var data = response.data, status = response.status, header = response.header, config = response.config; }); 

Demo: JSBin

Edit: If there is a problem with HTML, you can look in $sce.trustAsHtml(html) or PhantomJS with links:

+3
source

All Articles