variable undefined
-
I want to extract a video name from XML and put it in the URL parameter. I copied the XML reading code from w3school. See below:
//var videoName; the name of the video
var tPath = ... the URL to the XML
var var2 = ... the filename of an XML
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", tPath, true);
xmlhttp.send();
function myFunction(xml) {
var x, xmlDoc, videoName;
xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("videoName")[0];
videoName = (x.textContent);
alert (videoName);
}
var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;I see the name of the video in alert. but the playerURL has videoName shown as undefined. my XML is like this, and I'm trying to pick up "videoName.mp4":
videoName.mp4
What is wrong with the script? Thanks,
-
I want to extract a video name from XML and put it in the URL parameter. I copied the XML reading code from w3school. See below:
//var videoName; the name of the video
var tPath = ... the URL to the XML
var var2 = ... the filename of an XML
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", tPath, true);
xmlhttp.send();
function myFunction(xml) {
var x, xmlDoc, videoName;
xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("videoName")[0];
videoName = (x.textContent);
alert (videoName);
}
var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;I see the name of the video in alert. but the playerURL has videoName shown as undefined. my XML is like this, and I'm trying to pick up "videoName.mp4":
videoName.mp4
What is wrong with the script? Thanks,
-
I want to extract a video name from XML and put it in the URL parameter. I copied the XML reading code from w3school. See below:
//var videoName; the name of the video
var tPath = ... the URL to the XML
var var2 = ... the filename of an XML
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", tPath, true);
xmlhttp.send();
function myFunction(xml) {
var x, xmlDoc, videoName;
xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("videoName")[0];
videoName = (x.textContent);
alert (videoName);
}
var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;I see the name of the video in alert. but the playerURL has videoName shown as undefined. my XML is like this, and I'm trying to pick up "videoName.mp4":
videoName.mp4
What is wrong with the script? Thanks,
Just try to fetch the value of "x" in the below code outside "myFunction"
x = xmlDoc.getElementsByTagName("videoName")[0];
I am wondering, if the value of "x" is dying out. I also cant see the closing braces of "myFunction" or no return value of "x" from the function. Is the below code a part of "myFunction" ?
var x, xmlDoc, videoName;
xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("videoName")[0];
videoName = (x.textContent);
alert (videoName);var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;
If so, just try out reading the value of the element out side the function and see. Please let me know the result once. Thanks
-
Just try to fetch the value of "x" in the below code outside "myFunction"
x = xmlDoc.getElementsByTagName("videoName")[0];
I am wondering, if the value of "x" is dying out. I also cant see the closing braces of "myFunction" or no return value of "x" from the function. Is the below code a part of "myFunction" ?
var x, xmlDoc, videoName;
xmlDoc = xml.responseXML;
x = xmlDoc.getElementsByTagName("videoName")[0];
videoName = (x.textContent);
alert (videoName);var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;
If so, just try out reading the value of the element out side the function and see. Please let me know the result once. Thanks