I've been trying to figure out how to initialize an object using a prototype in order to escape using global variables, which I first learned about here. I began implementing my own version of the code found in the accepted answer.
function XML_Data() {
this.data = null;
}
XML_Data.prototype = {
GetXML: function() {
$.ajax({
type: "GET",
url: "questions.xml",
dataType: "xml",
success: function(xml) {
this.data=xml;
} //close success
});//close AJAX
},
UseXML: function() {
alert(this.data)
}
};
(My implementation of the script)
However, I've run into a problem. When I run the functions shown here by using this bit of code:
var data = new XML_Data();
data.GetXML();
data.UseXML();
I get an alert that says "null". I've been through the code about a dozen times, but as this is my first time working with Javascript, there's quite obviously something I've missed. Could you point that out?
Thanks, Elliot Bonneville.