Read text content from a remote/web hosted file

Aug 29, 2021

Is it possible to point to an XML or text file on a website (for example):

www.mywebsite.com/exercise.XML

and read the contents and load that into a variable in SL360 dynamically?

Many thanks in advance for your assistance.

David


I have adapted some Javascript from other posts on this site that works for a local file but it does not seem to work for a remote file:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
getValues(this);
}
};

let url1 = new URL('https://www.myserver.com/values.xml');xhttp.open("GET", url1, true);

xhttp.send();

xhttp.onload = function() {
alert(`Loaded: ${xhttp.status} ${xhttp.response}`);
};

xhttp.onerror = function() { // only triggers if the request couldn't be made at all
alert(`Network Error`);
};

function getValues(xml) {
var player = GetPlayer();
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName('db');
player.SetVar("Value1", x[0].getAttribute('value'));
player.SetVar("Value2", x[1].getAttribute('value'));
player.SetVar("Value3", x[2].getAttribute('value'));
}

1 Reply