- ...
The question prompts the jQuery plugin. If this is what you want, then you can do something like this:
(function($){
var pluginName = 'get_members';
$.fn[pluginName] = function(url, otherValue) {
var $this = $(this).eq(0),
data = $this.data(pluginName);
if(!data) {
data = {};
$this.data(pluginName, data);
}
if(otherValue === undefined || $this.val() !== otherValue) {
if(data.jqXHR) {
data.jqXHR.abort();
}
data.jqXHR = $.get(url).done(function(response, textStatus, jqXHR) {
...
});
}
return data.jqXHR || $.Deferred().reject(pluginName + ': conditions for fetching members have not been met');
}
})(jQuery);
var promise_of_members = $("#myInputElement").get_members('http://my/url', $("#gid").val());
var promise_of_members = $("#myInputElement").get_members('http://my/url', 'myComparisonString');
var promise_of_members = $("#myInputElement").get_members('http://my/url');
When writing this document, you need to make some design decisions so that you can get something a little different, depending on what you want to do and how much control over the detailed behavior you want to have.
source
share