refactoring so that jquery AJAX works for each event