I'm trying to create a widget, and let it take care of its own ajax call, and do stuff with the data coming back after, however, i can't seems to be able to set the options internally?
$.widget("test" , {
options: {
url : null,
data : null
},
_create: function() {
var that = this;
$.ajax({
url : this.options.url,
dataType : 'json',
cache : false
}).done(function(resp) {
that._option("data", resp.stuff);
});
this._blah();
},
_option: function(key, val) {
this.options[key] = val;
},
_blah: function() {
console.log(this.options.data);
}
}
the variable url
is being set when the widget is triggered. I can't use this
inside ajax, so i created that
instead. But the data
won't stick....
Also the weird thing is that, if i put a breakpoint inside the widget, the breakpoint would get trigger for the first time, but not the second... is there a better way to debug the jQuery widget?