I want to pass a function as a parameter to a plugin.
Problem: I am creating a jquery plugin. The jquery plugin makes the JSON-P calls.
The part of the code:
(function ($) {
$.fn.GetJsonResult = function (options) {
var opts = $.extend({}, $.fn.GetJsonResult.defaults, options);
var control = this;
$.ajax({
url: opts.url,
dataType: 'jsonp',
cache: false,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error occured textStatus=" + textStatus + " errorThrown=" + errorThrown);
},
success: function (j) {
}
});
}
})(jQuery);
Can i pass some function name that will execute in the success method when JSOn request is completed.
You could pass the function itself:
Or:
And then: