Hey all, I'm trying to create a module that needs to do some request
in Ajax and fire event when those request are done.
I'm having trouble to use the fireEvent function of my class inside of
ajax callbacks function.
this is my code.
the get_confguration works because the request is not asynchronous but
i'd like to it asynchronously (like in get_configuration2). But in
that case, this doesn't point to the right object so the fireEvent
function doesn't exist for this "this".
how could i get back my point to the Network object from the callback
function of my getJSON query ?
var Network = new Class({
Implements: Events,
initialize : function(PluginId){
this.Plugin = document.getElementById(PluginId);
this.Conf = null;
this.Name = "Network Plugin";
},
get_configuration : function(Url){
var html = $.ajax({ url: Url , async: false }).responseText;
this.Conf = JSON.decode(html);
this.fireEvent("Ready");
},
get_configuration2 : function(Url){
alert("conf loading");
$.getJSON(Url, function(data) {
this.fireEvent("Ready");
});
}
});
var Ntw = new Network("pluginNetw");
Ntw.addEvent("Ready",function(){alert("ready ");});
Ntw.get_configuration("Javascript/conf.txt"); //this trigger Ready
Ntw.get_configuration2("Javascript/conf.txt"); //this doesn't
Thanks for your help
Greetings
Léo