How to display text on a website from htm or xml file that is updated every time
I'm working on the radio site and for streaming, the Jazler RadioStar 2 program is used which allows constant updating of files that transmit the information which song is currently streaming..
check image
I am specifically interested in how to transfer the title of the song and the name of the author to my homepage..
customexportfile.htm code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
</head>
<body>
<p>TNowOnAir: <strong>Cher | Believe</strong>
</body>
</html>
or via xml file, NowOnAir.xml
<Schedule System="Jazler">
<Event status="happening" startTime="09:15:30" eventType="song">
<Announcement Display=""/>
<Song title="Believe">
<Artist name="Cher"> </Artist>
<Jazler ID="6379"/>
<PlayLister ID=""/>
<Media runTime="03:34"/>
<Expire Time="09:19:03"/>
</Song>
</Event>
</Schedule>
These files are automatically updated when the song on the stream changes.
javascript html xml stream id
add a comment |
I'm working on the radio site and for streaming, the Jazler RadioStar 2 program is used which allows constant updating of files that transmit the information which song is currently streaming..
check image
I am specifically interested in how to transfer the title of the song and the name of the author to my homepage..
customexportfile.htm code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
</head>
<body>
<p>TNowOnAir: <strong>Cher | Believe</strong>
</body>
</html>
or via xml file, NowOnAir.xml
<Schedule System="Jazler">
<Event status="happening" startTime="09:15:30" eventType="song">
<Announcement Display=""/>
<Song title="Believe">
<Artist name="Cher"> </Artist>
<Jazler ID="6379"/>
<PlayLister ID=""/>
<Media runTime="03:34"/>
<Expire Time="09:19:03"/>
</Song>
</Event>
</Schedule>
These files are automatically updated when the song on the stream changes.
javascript html xml stream id
Use ajax to get information from the server without reloading the page
– FZs
Dec 31 '18 at 8:41
1
Can you explain me better, I'm noob in scripting..
– Mark
Dec 31 '18 at 8:42
AJAX is stand for Asynchronous Javascript And Xml. You can set timeouts in JavaScript to request data (XML, JSON, text or anything) from server
– FZs
Dec 31 '18 at 8:49
I'm sorry, but can you do the code, I'm not a programmer and I do not understand the best of these things..
– Mark
Dec 31 '18 at 8:57
add a comment |
I'm working on the radio site and for streaming, the Jazler RadioStar 2 program is used which allows constant updating of files that transmit the information which song is currently streaming..
check image
I am specifically interested in how to transfer the title of the song and the name of the author to my homepage..
customexportfile.htm code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
</head>
<body>
<p>TNowOnAir: <strong>Cher | Believe</strong>
</body>
</html>
or via xml file, NowOnAir.xml
<Schedule System="Jazler">
<Event status="happening" startTime="09:15:30" eventType="song">
<Announcement Display=""/>
<Song title="Believe">
<Artist name="Cher"> </Artist>
<Jazler ID="6379"/>
<PlayLister ID=""/>
<Media runTime="03:34"/>
<Expire Time="09:19:03"/>
</Song>
</Event>
</Schedule>
These files are automatically updated when the song on the stream changes.
javascript html xml stream id
I'm working on the radio site and for streaming, the Jazler RadioStar 2 program is used which allows constant updating of files that transmit the information which song is currently streaming..
check image
I am specifically interested in how to transfer the title of the song and the name of the author to my homepage..
customexportfile.htm code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
</head>
<body>
<p>TNowOnAir: <strong>Cher | Believe</strong>
</body>
</html>
or via xml file, NowOnAir.xml
<Schedule System="Jazler">
<Event status="happening" startTime="09:15:30" eventType="song">
<Announcement Display=""/>
<Song title="Believe">
<Artist name="Cher"> </Artist>
<Jazler ID="6379"/>
<PlayLister ID=""/>
<Media runTime="03:34"/>
<Expire Time="09:19:03"/>
</Song>
</Event>
</Schedule>
These files are automatically updated when the song on the stream changes.
javascript html xml stream id
javascript html xml stream id
asked Dec 31 '18 at 8:37
MarkMark
35
35
Use ajax to get information from the server without reloading the page
– FZs
Dec 31 '18 at 8:41
1
Can you explain me better, I'm noob in scripting..
– Mark
Dec 31 '18 at 8:42
AJAX is stand for Asynchronous Javascript And Xml. You can set timeouts in JavaScript to request data (XML, JSON, text or anything) from server
– FZs
Dec 31 '18 at 8:49
I'm sorry, but can you do the code, I'm not a programmer and I do not understand the best of these things..
– Mark
Dec 31 '18 at 8:57
add a comment |
Use ajax to get information from the server without reloading the page
– FZs
Dec 31 '18 at 8:41
1
Can you explain me better, I'm noob in scripting..
– Mark
Dec 31 '18 at 8:42
AJAX is stand for Asynchronous Javascript And Xml. You can set timeouts in JavaScript to request data (XML, JSON, text or anything) from server
– FZs
Dec 31 '18 at 8:49
I'm sorry, but can you do the code, I'm not a programmer and I do not understand the best of these things..
– Mark
Dec 31 '18 at 8:57
Use ajax to get information from the server without reloading the page
– FZs
Dec 31 '18 at 8:41
Use ajax to get information from the server without reloading the page
– FZs
Dec 31 '18 at 8:41
1
1
Can you explain me better, I'm noob in scripting..
– Mark
Dec 31 '18 at 8:42
Can you explain me better, I'm noob in scripting..
– Mark
Dec 31 '18 at 8:42
AJAX is stand for Asynchronous Javascript And Xml. You can set timeouts in JavaScript to request data (XML, JSON, text or anything) from server
– FZs
Dec 31 '18 at 8:49
AJAX is stand for Asynchronous Javascript And Xml. You can set timeouts in JavaScript to request data (XML, JSON, text or anything) from server
– FZs
Dec 31 '18 at 8:49
I'm sorry, but can you do the code, I'm not a programmer and I do not understand the best of these things..
– Mark
Dec 31 '18 at 8:57
I'm sorry, but can you do the code, I'm not a programmer and I do not understand the best of these things..
– Mark
Dec 31 '18 at 8:57
add a comment |
2 Answers
2
active
oldest
votes
- Make a text file to the same directory as
NowOnAir.xml
! - Name it like
filename.html
- Type the following inside:
<!DOCTYPE html>
<html>
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body onload="refresh()">
<p>Now playing: <span id="art"></span>|<span id="title"></span>
<script>
var interval,time
function refresh(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("art").innerHTML = this.responseXML.getElementByTagName("ARTIST")[0].getAttribute("name");
document.getElementById("title").innerHTML = this.responseXML.getElementByTagName("SONG")[0].getAttribute("title");
time=this.responseXML.getElementByTagName("EXPIRE")[0].getAttribute("Time").split(":")
interval=setInterval(checkTime,1000)
}
};
xhttp.open("GET", "NowOnAir.xml", true);
xhttp.send();
}
}
function checkTime(){
var date=new Date()
if(date.getSeconds()==time[2]&&date.getMinutes()==time[1]&&date.getHours()==time[0]){
clearInterval(interval)
refresh()
}
}
</script>
</body>
</html>
- Then try it (you will find it like this:
http://serveraddress/path/filename.html
)
I hope that this will help you!
I tried this and got two error in the console : i.postimg.cc/K85yw7Hc/Capture.png
– Mark
Dec 31 '18 at 12:17
Otherwise the site on which I work is on the wordpress platform, if it is something that is important..
– Mark
Dec 31 '18 at 12:23
add a comment |
Hesitantly, you can try out this code...
N.B.
- There are a great many reasons why this might not work (from the outset, or later).
- You should certainly test this out in an environment where it will not upset anyone if it doesn't work.
- The solution below involves checking for a new song and title every 5 seconds using the Javascript setInterval method. That could well be a wholly inappropriate solution because it will run indefinitely every 5 seconds. Without more information, it's impossible to answer this for you really.
- This code is untested.
Anyway, here's a punt at solving this problem:
HTML (homepage):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>NowOnAir:
<strong>
<span id="artistName">Cher</span> |
<span id="songTitle">Believe</span>
</strong>
</p>
<script>
function getNowPlaying() {
const src = "NowOnAir.xml";
$.ajax({
type: 'GET',
url: src,
dataType: xml,
success: function(xml) {
//parse XML
const xmlDoc = $.parseXML( xml );
const $doc = $( xmlDoc );
const $artist = $doc.find( "Artist" ).attr("name").text();
const $song = $doc.find( "Song" ).attr("title").text();
//update homepage
$("#artistName").text($artist);
$("#songTitle").text($song);
},
error: function(e) {
console.log(e);
}
})
}
setInterval( function() {
getNowPlaying();
}, 5000);
</script>
</body>
</html>
If it doesn't work, feel free to comment and I'll try to help.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985282%2fhow-to-display-text-on-a-website-from-htm-or-xml-file-that-is-updated-every-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
- Make a text file to the same directory as
NowOnAir.xml
! - Name it like
filename.html
- Type the following inside:
<!DOCTYPE html>
<html>
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body onload="refresh()">
<p>Now playing: <span id="art"></span>|<span id="title"></span>
<script>
var interval,time
function refresh(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("art").innerHTML = this.responseXML.getElementByTagName("ARTIST")[0].getAttribute("name");
document.getElementById("title").innerHTML = this.responseXML.getElementByTagName("SONG")[0].getAttribute("title");
time=this.responseXML.getElementByTagName("EXPIRE")[0].getAttribute("Time").split(":")
interval=setInterval(checkTime,1000)
}
};
xhttp.open("GET", "NowOnAir.xml", true);
xhttp.send();
}
}
function checkTime(){
var date=new Date()
if(date.getSeconds()==time[2]&&date.getMinutes()==time[1]&&date.getHours()==time[0]){
clearInterval(interval)
refresh()
}
}
</script>
</body>
</html>
- Then try it (you will find it like this:
http://serveraddress/path/filename.html
)
I hope that this will help you!
I tried this and got two error in the console : i.postimg.cc/K85yw7Hc/Capture.png
– Mark
Dec 31 '18 at 12:17
Otherwise the site on which I work is on the wordpress platform, if it is something that is important..
– Mark
Dec 31 '18 at 12:23
add a comment |
- Make a text file to the same directory as
NowOnAir.xml
! - Name it like
filename.html
- Type the following inside:
<!DOCTYPE html>
<html>
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body onload="refresh()">
<p>Now playing: <span id="art"></span>|<span id="title"></span>
<script>
var interval,time
function refresh(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("art").innerHTML = this.responseXML.getElementByTagName("ARTIST")[0].getAttribute("name");
document.getElementById("title").innerHTML = this.responseXML.getElementByTagName("SONG")[0].getAttribute("title");
time=this.responseXML.getElementByTagName("EXPIRE")[0].getAttribute("Time").split(":")
interval=setInterval(checkTime,1000)
}
};
xhttp.open("GET", "NowOnAir.xml", true);
xhttp.send();
}
}
function checkTime(){
var date=new Date()
if(date.getSeconds()==time[2]&&date.getMinutes()==time[1]&&date.getHours()==time[0]){
clearInterval(interval)
refresh()
}
}
</script>
</body>
</html>
- Then try it (you will find it like this:
http://serveraddress/path/filename.html
)
I hope that this will help you!
I tried this and got two error in the console : i.postimg.cc/K85yw7Hc/Capture.png
– Mark
Dec 31 '18 at 12:17
Otherwise the site on which I work is on the wordpress platform, if it is something that is important..
– Mark
Dec 31 '18 at 12:23
add a comment |
- Make a text file to the same directory as
NowOnAir.xml
! - Name it like
filename.html
- Type the following inside:
<!DOCTYPE html>
<html>
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body onload="refresh()">
<p>Now playing: <span id="art"></span>|<span id="title"></span>
<script>
var interval,time
function refresh(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("art").innerHTML = this.responseXML.getElementByTagName("ARTIST")[0].getAttribute("name");
document.getElementById("title").innerHTML = this.responseXML.getElementByTagName("SONG")[0].getAttribute("title");
time=this.responseXML.getElementByTagName("EXPIRE")[0].getAttribute("Time").split(":")
interval=setInterval(checkTime,1000)
}
};
xhttp.open("GET", "NowOnAir.xml", true);
xhttp.send();
}
}
function checkTime(){
var date=new Date()
if(date.getSeconds()==time[2]&&date.getMinutes()==time[1]&&date.getHours()==time[0]){
clearInterval(interval)
refresh()
}
}
</script>
</body>
</html>
- Then try it (you will find it like this:
http://serveraddress/path/filename.html
)
I hope that this will help you!
- Make a text file to the same directory as
NowOnAir.xml
! - Name it like
filename.html
- Type the following inside:
<!DOCTYPE html>
<html>
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body onload="refresh()">
<p>Now playing: <span id="art"></span>|<span id="title"></span>
<script>
var interval,time
function refresh(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("art").innerHTML = this.responseXML.getElementByTagName("ARTIST")[0].getAttribute("name");
document.getElementById("title").innerHTML = this.responseXML.getElementByTagName("SONG")[0].getAttribute("title");
time=this.responseXML.getElementByTagName("EXPIRE")[0].getAttribute("Time").split(":")
interval=setInterval(checkTime,1000)
}
};
xhttp.open("GET", "NowOnAir.xml", true);
xhttp.send();
}
}
function checkTime(){
var date=new Date()
if(date.getSeconds()==time[2]&&date.getMinutes()==time[1]&&date.getHours()==time[0]){
clearInterval(interval)
refresh()
}
}
</script>
</body>
</html>
- Then try it (you will find it like this:
http://serveraddress/path/filename.html
)
I hope that this will help you!
answered Dec 31 '18 at 10:27
FZsFZs
1,3742824
1,3742824
I tried this and got two error in the console : i.postimg.cc/K85yw7Hc/Capture.png
– Mark
Dec 31 '18 at 12:17
Otherwise the site on which I work is on the wordpress platform, if it is something that is important..
– Mark
Dec 31 '18 at 12:23
add a comment |
I tried this and got two error in the console : i.postimg.cc/K85yw7Hc/Capture.png
– Mark
Dec 31 '18 at 12:17
Otherwise the site on which I work is on the wordpress platform, if it is something that is important..
– Mark
Dec 31 '18 at 12:23
I tried this and got two error in the console : i.postimg.cc/K85yw7Hc/Capture.png
– Mark
Dec 31 '18 at 12:17
I tried this and got two error in the console : i.postimg.cc/K85yw7Hc/Capture.png
– Mark
Dec 31 '18 at 12:17
Otherwise the site on which I work is on the wordpress platform, if it is something that is important..
– Mark
Dec 31 '18 at 12:23
Otherwise the site on which I work is on the wordpress platform, if it is something that is important..
– Mark
Dec 31 '18 at 12:23
add a comment |
Hesitantly, you can try out this code...
N.B.
- There are a great many reasons why this might not work (from the outset, or later).
- You should certainly test this out in an environment where it will not upset anyone if it doesn't work.
- The solution below involves checking for a new song and title every 5 seconds using the Javascript setInterval method. That could well be a wholly inappropriate solution because it will run indefinitely every 5 seconds. Without more information, it's impossible to answer this for you really.
- This code is untested.
Anyway, here's a punt at solving this problem:
HTML (homepage):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>NowOnAir:
<strong>
<span id="artistName">Cher</span> |
<span id="songTitle">Believe</span>
</strong>
</p>
<script>
function getNowPlaying() {
const src = "NowOnAir.xml";
$.ajax({
type: 'GET',
url: src,
dataType: xml,
success: function(xml) {
//parse XML
const xmlDoc = $.parseXML( xml );
const $doc = $( xmlDoc );
const $artist = $doc.find( "Artist" ).attr("name").text();
const $song = $doc.find( "Song" ).attr("title").text();
//update homepage
$("#artistName").text($artist);
$("#songTitle").text($song);
},
error: function(e) {
console.log(e);
}
})
}
setInterval( function() {
getNowPlaying();
}, 5000);
</script>
</body>
</html>
If it doesn't work, feel free to comment and I'll try to help.
add a comment |
Hesitantly, you can try out this code...
N.B.
- There are a great many reasons why this might not work (from the outset, or later).
- You should certainly test this out in an environment where it will not upset anyone if it doesn't work.
- The solution below involves checking for a new song and title every 5 seconds using the Javascript setInterval method. That could well be a wholly inappropriate solution because it will run indefinitely every 5 seconds. Without more information, it's impossible to answer this for you really.
- This code is untested.
Anyway, here's a punt at solving this problem:
HTML (homepage):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>NowOnAir:
<strong>
<span id="artistName">Cher</span> |
<span id="songTitle">Believe</span>
</strong>
</p>
<script>
function getNowPlaying() {
const src = "NowOnAir.xml";
$.ajax({
type: 'GET',
url: src,
dataType: xml,
success: function(xml) {
//parse XML
const xmlDoc = $.parseXML( xml );
const $doc = $( xmlDoc );
const $artist = $doc.find( "Artist" ).attr("name").text();
const $song = $doc.find( "Song" ).attr("title").text();
//update homepage
$("#artistName").text($artist);
$("#songTitle").text($song);
},
error: function(e) {
console.log(e);
}
})
}
setInterval( function() {
getNowPlaying();
}, 5000);
</script>
</body>
</html>
If it doesn't work, feel free to comment and I'll try to help.
add a comment |
Hesitantly, you can try out this code...
N.B.
- There are a great many reasons why this might not work (from the outset, or later).
- You should certainly test this out in an environment where it will not upset anyone if it doesn't work.
- The solution below involves checking for a new song and title every 5 seconds using the Javascript setInterval method. That could well be a wholly inappropriate solution because it will run indefinitely every 5 seconds. Without more information, it's impossible to answer this for you really.
- This code is untested.
Anyway, here's a punt at solving this problem:
HTML (homepage):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>NowOnAir:
<strong>
<span id="artistName">Cher</span> |
<span id="songTitle">Believe</span>
</strong>
</p>
<script>
function getNowPlaying() {
const src = "NowOnAir.xml";
$.ajax({
type: 'GET',
url: src,
dataType: xml,
success: function(xml) {
//parse XML
const xmlDoc = $.parseXML( xml );
const $doc = $( xmlDoc );
const $artist = $doc.find( "Artist" ).attr("name").text();
const $song = $doc.find( "Song" ).attr("title").text();
//update homepage
$("#artistName").text($artist);
$("#songTitle").text($song);
},
error: function(e) {
console.log(e);
}
})
}
setInterval( function() {
getNowPlaying();
}, 5000);
</script>
</body>
</html>
If it doesn't work, feel free to comment and I'll try to help.
Hesitantly, you can try out this code...
N.B.
- There are a great many reasons why this might not work (from the outset, or later).
- You should certainly test this out in an environment where it will not upset anyone if it doesn't work.
- The solution below involves checking for a new song and title every 5 seconds using the Javascript setInterval method. That could well be a wholly inappropriate solution because it will run indefinitely every 5 seconds. Without more information, it's impossible to answer this for you really.
- This code is untested.
Anyway, here's a punt at solving this problem:
HTML (homepage):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Trenutno Slusate!</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>NowOnAir:
<strong>
<span id="artistName">Cher</span> |
<span id="songTitle">Believe</span>
</strong>
</p>
<script>
function getNowPlaying() {
const src = "NowOnAir.xml";
$.ajax({
type: 'GET',
url: src,
dataType: xml,
success: function(xml) {
//parse XML
const xmlDoc = $.parseXML( xml );
const $doc = $( xmlDoc );
const $artist = $doc.find( "Artist" ).attr("name").text();
const $song = $doc.find( "Song" ).attr("title").text();
//update homepage
$("#artistName").text($artist);
$("#songTitle").text($song);
},
error: function(e) {
console.log(e);
}
})
}
setInterval( function() {
getNowPlaying();
}, 5000);
</script>
</body>
</html>
If it doesn't work, feel free to comment and I'll try to help.
answered Dec 31 '18 at 10:47
jonhendrixjonhendrix
958
958
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985282%2fhow-to-display-text-on-a-website-from-htm-or-xml-file-that-is-updated-every-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use ajax to get information from the server without reloading the page
– FZs
Dec 31 '18 at 8:41
1
Can you explain me better, I'm noob in scripting..
– Mark
Dec 31 '18 at 8:42
AJAX is stand for Asynchronous Javascript And Xml. You can set timeouts in JavaScript to request data (XML, JSON, text or anything) from server
– FZs
Dec 31 '18 at 8:49
I'm sorry, but can you do the code, I'm not a programmer and I do not understand the best of these things..
– Mark
Dec 31 '18 at 8:57