This doesn't work, but gives you the idea: a widget needs to use its own method as a callbacK:
$.widget("me.mywidget", {
_create: function() {
this.call("mymodule", "myaction", {arg: this.options.value}, _parseData);
},
_parseData: function(data) {
console.log(data);
},
call: function(module, action, params, callback) {
var params = params || {};
var url = "/" + module + "/" + action;
$.post(url, params, function(data) {
if (data.payload) callback(data.payload);
});
},
});
It currently throws the exception: Uncaught ReferenceError: _parseData is not defined
What's the canonical way of doing this?