== petición AJAX y modificación DOM
* boostrat
* custom-control-input
* toast
* DataTable
$(document)
.ready(function () {
$('#recorda').toast('show');
$('#tablecontrols').DataTable({
paging: false,
ordering: false,
select: true
});
$('.dataTables_length').addClass('bs-select');
$('td[data-href]').on('click', function() {
window.location = ( $(this).data("href") );
//window.open( $(this).data("href"), "_blank" );
});
$("input:checkbox").on('change', function() {
inputObject = $(this);
clase = ( $(this).val() == "1") ? 'table-success' : 'table-danger';
id = $(this).attr('data-ajax-id');
field = $(this).attr('data-ajax-field');
isChecked = $(this).is(":checked");
isValue = (isChecked) ? 1 : 0;
datos = {
'id':id,
'field':field,
'value':isValue
};
ajaxError = 0;
$('#desant').toast('show');
jQuery.ajax({
type: 'post',
url: '/controller/controls/update-list-checks.php',
data: datos,
success: function(resp) {
$('#desant').toast('hide');
if ( isChecked ) $(inputObject).parents('tr').addClass(clase);
else $(inputObject).parents('tr').removeClass(clase);
$('#desat').toast('show');
},
error: function(xhr,status,error) {
$('#desant').toast('hide');
$('#error').toast('show');
$(inputObject).prop('checked',!isChecked);
},
dataType:'json'
});
});
});
Atenció!
S'estàn desant les dades...
Atenció!
Les dades s'han desat correctament
>
'operació realitzada correctament',
1 => 'error en els paràmetres enviats'
);
$fieldsPermesos = array('exclos','ressonat');
$codRetorn = 0;
$id = ( array_key_exists('id',$_POST) ) ? $_POST['id'] : 0;
$field = ( array_key_exists('field',$_POST) ) ? $_POST['field'] : '';
$value = ( array_key_exists('value',$_POST) ) ? $_POST['value'] : '';
if ( (array_search($field,$fieldsPermesos))!== false ) {
$data = array(
'id' => $id,
$field => $value
);
updateControl($data);
$headerRetorn = 'HTTP/1.1 200 OK';
} else {
$codRetorn = 1;
$headerRetorn = 'HTTP/1.1 406 Not Acceptable';
}
$arrRespuesta = array(
"status" => $codRetorn,
"txt" => $codRetronDesc[$codRetorn]
);
header($headerRetorn);
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($arrRespuesta);
?>