I really would appreciate your help and guidance on this issue I'm having. Let's say I have an xml file that simplified looks like this:
<?xml version="1.0" encoding="UTF-8"?> <node> <varValue>MyAwesomeValue</varValue> </node> I have also a separate JS file that attempts to parse this simple xml to get the "MyAwesomeValue" and then combine it with another variable (from another file) to asseble the clickable url. The code I currently have looks something like this:
var requestData = new XMLHttpRequest(); requestData.onreadystatechange = function() { if (requestData.readyState == 4 && requestData.status == 200) { grabData(requestData); } }; requestData.open("GET", "data_feed.xml", true); requestData.send(); function grabData(xml) { var xmlDoc = xml.responseXML; var myVariable = xmlDoc.getElementsByTagName("varValue")[0].childNodes[0].nodeValue; } var clickAction = myVariable[0].textContent.toString(); function clickBtn() { window.open(myOtherDocVar + clickAction); } So function clickBtn() is called from another js file, same file where "myOtherDocVar" variable value is passed from. But when the clickBtn is triggered, it doesn't seem to do anything ...unless it's inside "grabData()" function. But I would like "clickBtn()" function to be its own function. It seems like "myVariable" only passes the node value inside "grabData()" function, but outside of that function it shows undefined.
How could I make this work?
Thank you!!!
No comments:
Post a Comment