I am looking for a recommendation on the best way to organize my code. I have many jQuery event handlers that are used for:
- drop down menus, tabs, etc.
- form validation
- $. ajax get requests for dynamic form
<options> - $. ajax messages to submit the form.
An MVC structure like backbonejs seems redundant, but my current code is not supported and will continue to deteriorate unless I give it some kind of structure.
$('#detailsform').find('.field').on('click','.save',function(){
var input = $(this).siblings().find('input');
input.attr('type','hidden');
$(this).siblings().find('p').text(input.val());
$(this).text('Change').addClass('change').removeClass('save');
url = null;
$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});
});
which is one of many event listeners. Any suggestions on organizing this?
source
share