I am on creating a simple class with 2 methods:
- Init(‘/path/to/xmlfile’)
- test(stuff)
The main problem is that test method depends on the XML file loaded to work.
So, when I do something like this:
f.init('/sources/model.xml');
f.test(it);
it fails because test uses a structure that is made when the XML file is loaded.
Since I am using jQuery to load XML file, with get method, I can do some stuff
this way:
f.init('/sources/model.xml',
function() {
if (this.test(it) ) {
alert('OK, it works!');
}else {
alert('Wrong!');
}
});
and put my callback inside the success callback of get jQuery method….
BUT, is possible do something like that I put above?
I would appreciate any help.
Note:
I tried with a variable "loaded" inside test function, and a setInterval function to check if the XML file is loaded, but it didn’t work for me.
You should use callbacks to prevent blocking but if you really want to have the
initfunction block until it receives a response, you could opt to use the $.ajax method instead of $.get$.ajax supports an
asyncoption, which if set tofalsewill block script execution until the server respondsBasic Usage:
Documentation,
http://api.jquery.com/jQuery.ajax/