HTML/Javascript - 从在线文件中获取文本

Isa*_*acL 5 html javascript

我知道Shoutcast输出为html文件.

html文件如下所示:http://216.118.106.247:443/7.html.

有没有办法将该列表/数组中的最后一项作为字符串添加到Javascript中?

我想在html文件中输出歌曲信息,我假设一旦我把它作为一个字符串进入JS,我可以使用该document.write()函数输出代码...

谢谢!

Fem*_*emi 5

如果您查看http://code.google.com/chrome/extensions/xhr.html,则需要设置跨源请求,然后您应该能够使用XMLHttpRequest来获取数据.

编辑:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = process;
xhr.open("GET", "http://216.118.106.247:443/7.html", true);
xhr.send();

function process()
{
  if (xhr.readyState == 4) {
    var resp = JSON.parse(xhr.responseText);

    // resp now has the text and you can process it.
alert(resp);
  }
}
Run Code Online (Sandbox Code Playgroud)


KZ.*_*KZ. 1

看一下XMLHttpRequest又名 Ajax 请求。

有大量的库可以使“Ajax”变得简单。试试这个:

http://www.prototypejs.org/api/ajax/request

使用 ajax 检索的内容有限制。由于安全问题,您的浏览器不会让运行在 yourwebsite.com 上的 JavaScript 对 mywebsite.com 执行 ajax 请求。

查找跨站点脚本。