I'v written a JS "class" for a jQuery framework which is like that:
(function($) {
$.fn.dynamic = function() {
return this.each(function() {
$(this).on("submit", function(e) {
var form = $(e.target);
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize(),
success : function(data, textStatus, jqXHR) {
// Do something
},
error : function(data, textStatus, jqXHR) {
// Do something
}
});
e.preventDefault();
return false;
});
});
});
})(jQuery);
in my success/errors function I'd like to make actions (display/hide autoloader, show messages, ...)
I thought the best way would be firing an event, by example:
form.trigger("formSubmitted", [data, true/false]);
And then with a listener do what I have to do.
Would it be possible to add a listener in my class dynaform and supposing I have to other classes (let's say Messages and ProgressOverlay), how would it be possible to call those classes methods and how to manage errors (imagine those classes are in an other file which cannot be loaded or other folks)