Ajax Examples
JavaScript
$body.on('click', '.submit_report', function (e) {
e.preventDefault();
var $object = {},
$error = 0,
$parent = $(this).closest('form'),
$date = $parent.find('.input_calendar'),
$id_lot = $parent.find('[name="lot[id]"]'),
$notes = $parent.find('.notes'),
$range = $parent.find('[type="range"]'),
$type = $(this).data('type'),
$state_select = $parent.find('.state_select option:selected'),
if ($date.val() != '') {
$date.removeClass('validate_error');
$object.date = $date.val();
} else {
$date.addClass('validate_error');
$error++;
}
$object.notes = $notes.val();
$object.percent = $range.val();
$object.type = $type;
$object.id_service = $state_select.val();
$object.id_lot = $id_lot.val();
if ($error == 0) {
$.ajax({
type: 'POST',
url: '/project.php',
dataType: 'json',
data: {
action: 'add_new_log',
form: $object
},
success: function (data) {
if (data.result == 'ok') {
$('.development_log_wrap').removeClass('active');
}
},
error: function (data) {
toast('error', 'Error');
}
});
} else {
toast('error', 'Incorrect values');
}
});
/*---------------------------------------------*/
$body.on('click', '.add_dev_log', function (e) {
e.preventDefault();
var logID = $(this).data('id');
$.ajax ({
url:'/project.php',
type:'post',
dataType: 'json',
data: {
action: 'get_log',
id: logID
},
success: function (data) {
if(data.result == 'ok') {
if(data.html != '') {
$('.development_log_wrap').html(data.html);
$('.info_lot').addClass('active');
}
}
},
error: function (data) {
toast('error', 'Error');
}
});
});