﻿(function($) {
    $.fn.loadContent = function(options) {
        options = $.extend({
            url: 'getData',
            onSuccess: null,
            errorText: "An Error Occured"
        }, options || {});
        return this.each(function(i, item) {
            $.ajax({
                url: options.url,
                dataType: 'json',
                success: function(data) {
                    $(item).removeClass("loadingIndicator");
                    options.onSuccess(data, item);
                },
                error: function(xhr, status, e) {
                    $(item).removeClass("loadingIndicator");
                    $(item).addClass("error");
                    $(item).text(options.errorText);
                },
                beforeSend: function() {
                    $(item).addClass("loadingIndicator");
                }
            });
            return true;
        });
    }
})(jQuery);

