I'm trying to do write a jQuery plugin based on a prototype pattern.
My problem is when I use the $.ajax function to load an xml file, I loose the this object.
For example this work :
Plugin.prototype = {
defaults: {
message: 'Hello world!'
},
init: function() {
this.setStyleAndOptions();
return this;
},
setStyleAndOptions: function() {
alert("setStyleAndOptions : ");
}
}
But that doesn't, I get an error saying "this.setStyleAndOptions is not defined" :
Plugin.prototype = {
defaults: {
message: 'Hello world!'
},
init: function() {
$.ajax({
type: "GET",
url: "param.xml",
dataType: "xml",
success: this.initOptions
});
return this;
},
initOptions: function(dataxml) {
// Error occured here, I suppose "this" is not the plugin anymore
this.setStyleAndOptions();
},
setStyleAndOptions: function() {
alert("setStyleAndOptions");
}
}
Thanks for your help.