cle*_*een 5 html javascript angularjs
我使用$ http.get('url')来获取"url"中的内容.'url'中的html如下
<html>
<head></head>
<body>
<pre style = "word-wrap: break-word; white-space: pre-wrap;">
<!-- content is present here -->
</pre>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我为此网址创建$ http.get时,我会获得一些数据和所需的内容
GET /TYPE=abvd HTTP 1.1
content required
.0.1234.123 Safari /123.12
Referer: //url of the webpage calling this function
Accept-Encoding:
...............
Run Code Online (Sandbox Code Playgroud)
如何摆脱这些额外信息并仅收到内容?(我知道我们可以解析响应,但有更好的方法吗?)
编辑:我得到的数据响应是在谷歌浏览器中看到的,当我在IE10中运行相同的脚本时,我得到了唯一的"html内容".为什么会出现这种差异?如何进行处理呢?
$http.get返回一个HttpPromise,您可以从中获取底层数据,如下所示:
$http.get('url').then(function(response) {
html = response.data;
});
Run Code Online (Sandbox Code Playgroud)
要获得更有用的数据,您可以像这样扩展:
$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;
});
Run Code Online (Sandbox Code Playgroud)
演示: JSBin
编辑:如果仍然存在 HTML 问题,您可以查看$sce.trustAsHtml(html)或参考 PhantomJS: