I just saw two javascript files:
first one had called following line after some success ajax call:
$(document).trigger("locationloaded");
The second js had:
$(document).on('locationloaded', function () {
//few lines of code here
});
Bit new to JS, just curious to know, could there be any valid reason for calling locationloaded through trigger? Why can't we have simple function as locationloaded() which would be called from first js? If both do the same work, which one should be used?
As per documentation of jQuery trigger
Any event handlers attached with
.on()
or one of its shortcut methods are triggered when the corresponding event occurs. They can be fired manually, however, with the.trigger()
method.