How to create plugin with ajax response
Plugin Code
- (function($) {
- $.fn.dateSlider = function($options) {
- var $defaults = {
- page: ''
- };
- var $settings = $.extend({}, $defaults, $options);
- return this.each(function() {
- $.post($settings.page, function($res) {
- $settings.done.call(this);
- });
- });
- };
- }(jQuery));
html
- $(function() {
- $('.test').dateSlider({
- page: 'res.php',
- done: function() {
- // want to do something when ajax send data back
- }
- });
- });
Plugin will connect to res.php and get the data back names $res, how to send the result to function named done?