Greetings to the whole community,
I have a question that I still can not solve, I comment a little on the case:
I have a datatable that feeds from an excel, that is, I charge the server an excel, the process and feed a datatable. It should be noted that I'm using Laravel and Jquery for this.
The issue is that once the Datatable is loaded, it is necessary to validate each record of the datatable to know if it complies with certain rules that are at server level already defined (number of characters, type of data that is being sent, etc.). .
The validation must be done at the time of loading the datatable and if there is any field that does not meet the condition then I must paint a red frame on the cell and the style of a tooltip indicate what is the error, with a click I must be able to edit the field of the datatable and make the adjustment.
The issue is that everything that I have just told you I have done, but I am stuck in the part of massively validating the DataTable, I show you some code where I do the massive validation
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
error: function( jqXHR, textStatus, errorThrown ) {
if (jqXHR.status === 0) {
console.log('Not connect: Verify Network.');
} else if (jqXHR.status == 404) {
console.log('Requested page not found [404]');
} else if (jqXHR.status == 500) {
console.log('Internal Server Error [500].');
} else if (textStatus === 'parsererror') {
console.log('Requested JSON parse failed.');
} else if (textStatus === 'timeout') {
console.log('Time out error.');
} else if (textStatus === 'abort') {
console.log('Ajax request aborted.');
} else {
console.log('Uncaught Error: ' + jqXHR.responseText);
}
}
});
function validar($td)
{
var $this = $td;
var $id = $this.attr("id");
var $text = $this.text().toString();
/*Se envia un ajax con el id y con el valor del input para validarlo en Laravel */
$.ajax
({
url: 'editable',
type: 'get',
async:'true',
data: {'id': $id, 'value': $text},
dataType: 'json'
}).done(function (data) {
var bandera=data.bandera;
/*Si la bandera es 0 significa que lo agarra la validacion*/
if(bandera==0)
{
$.each(data.error, function ($index, $contenido) {
$this.attr("style","border: solid #ff1b08;");
$this.tooltip({
content:" "+$contenido
});
})
}
/*Si la validacion es exitosa se quita el marco rojo de error encontrado*/
else
{
$this.attr("style","border-collapse: separate;");
$this.tooltip({
content:""
});
}
})
}
After loading the datatable dynamically with Jquery
$("td,.edit").each(function()
{
validar($(this));
})
After the datatable is loaded validate with a click cell by cell where it is in red
$("td,.edit").on("click", function ()
{
validarClic($(this));
});
Well the problem I have is that when I'm loading the Excel and the Datatable is being created, it starts to mark in red in some cells and in others it does not, where it does not return an "error 500".
The funny thing is that using the Browser Inspector specifically in the RED tab gives me the option to "edit the header and resend", if I do manual sends the data to the server and validates it perfectly.
The same thing happens if you validate it by clicking on the cell, sending the data perfectly to the server and validating it without problems.
The problem arises when I want to do the validation in a massive way.
There is some way (since I did not get anything in the ajax documentation) from:
- Control the time and speed at which the data is sent to the server, I say this because it seems to saturate when trying to validate.
- Somehow clean the requests made to the server, so that they start from scratch or this happens automatically already?
Any other idea that you can give me please is welcome, I hope you can help me.