//replace $(document).ready(function(){ $('#timetable_form').on('submit', function(e){//submit(function(){ e.preventDefault(); tinyMCE.triggerSave(); var formData = $(this).serialize(); if ($('#obj_id').val() != '') { var url = '/admin/ajax_post_timetable/'+$('#obj_id').val()+'/'; } else { var url = '/admin/ajax_post_timetable/' } $.ajax({ url: url, //server script to process data type: 'GET', //Ajax events success: postTimetable, error: function(){ alert('error'); }, // Form data data: formData, //Options to tell JQuery not to process data or worry about content-type cache: false, contentType: false, processData: false });//end ajax return false; }); // end submit $('.remove_timetable').on('click', function(e){ e.preventDefault(); $this = $(this); console.log('111'); var url = '/admin/ajax_delete_timetable/' var id = $(this).val(); $.get(url, {'id': id}, function(data){ if ('id' in data){ $this.parent().parent().remove(); } }); }); }); function removeTimeTable(data, obj){ console.log(data); console.log(obj); obj.parent().remove(); if ('id' in data){ console.log('success') } else{ console.log('error') } } function postTimetable(data, textStatus){ if (data instanceof Object){ console.log(data); $.each(data, function(field_name, errors){ $('#id_'+field_name).parent().parent().addClass('error'); }) } else{ $('#timetable_wrap table tbody').html(data); $('#timetable_form')[0].reset(); $('#timetable_form .control-group').removeClass('error'); $('#close_timetable').click(); } }