I am trying to write a jQuery plugin, that can be applied to a selector. Within this plugin, there are multiple calls to webservices, where callback methods are required.
The problem I am having is maintaining the current context item in the each loop of the selector.
(function($){
$.fn.myMethod = function(){
return this.each(function(){
var c = $(this);
$.api.methodToCall("", CallbackFunction);
});
};
function CallbackFunction(data, result){
// do stuff based on c
}
})(jQuery);
Normally, you would provide the callback function straight away, which allows me to access c, however within the callback function, there potentially is another api call, so it would start to get messy. Is there any way to do this?