I’ve reduced this example to the bare minimum code.
I’m focusing on the ‘this’ keyword.
Here’s how I call my Ajax plugin:
settings.context = this;
myXHR = $(this).myAjax('myComponent.cfc',settings);
What I’d like to do is use $(this) for the context so that the calling routine doesn’t have to set
settings.context = this;
Here’s what I’ve got so far, but I know I’m doing it wrong:
!function($, window, document, undefined) {
$.fn.myAjax.myOptions = {
type: 'POST',
dataType: 'json'
}
$.fn.myAjax = function(myURL, mySettings) {
var local = {};
local.settings = $.extend({}, $.fn.myOptions, mySettings);
local.settings.context = this;
local.XHR = $.ajax(myURL,local.settings)
return local.XHR;
};
}(jQuery, window, document);
1 Answer