Reputation: 43
I would like to retrieve a value in a xml file and use this value in another function.
I use:
function xmlparser() {
var xmlhttp, myvar;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://www.domain.net/xmlfile.xml", true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myvar = xmlhttp.responseXML.documentElement.getElementsByTagName("date")[0].textContent;
}
}
xmlhttp.send();
}
How can I use myvar
in another function ?
Like
function test() {
alert(myvar);
}
Thanks
Upvotes: 1
Views: 120
Reputation: 2046
Like so:
function test(myvar) {
alert(myvar);
}
function xmlparser()
{
var xmlhttp, xml_build, xml_dashboard;
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET", "http://www.domain.net/xmlfile.xml", true);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
myvar=xmlhttp.responseXML.documentElement.getElementsByTagName("date")[0].textContent;
test(myvar);
}
}
xmlhttp.send();
}
Upvotes: 1