Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML/Javascript - Get text from online file

I have info that Shoutcast outputs as an html file.

The html file looks like this: http://216.118.106.247:443/7.html.

Is there any way to get the last item in that list/array into Javascript as a string?

I want to output the song info in a html file, I assume that once I get it into JS as a string that I can use the document.write() function to output the code...

Thanks!

like image 350
IsaacL Avatar asked May 22 '11 04:05

IsaacL


1 Answers

If you look at http://code.google.com/chrome/extensions/xhr.html, you'll need to set up cross-origin requests and then you should be able to use the XMLHttpRequest to fetch the data.

EDITED:

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);
  }
}
like image 200
Femi Avatar answered Oct 04 '22 02:10

Femi