I have a tabla
called 'individuos'
, it has basic data like (id, no.identificacion, nombre completo, depen_serial(INTEGER))
among others ...
(to avoid any 'wrong' comment, this is how it is stipulated :: ..)
depen_serial
NOT a foreigner so the individual pueda que dependa de un numero de serie o no...
Having said that the problem is the following, in my form I have a input number (para digitar el serial)
... if I leave this field empty ajax
performs a serializeArray();
but the php throws an error as it is taking a completely empty data and the base of data as you need to receive an integer will not read the empty field ....
From what I deduced was the following, if this individual is not going to have a serial, a data NULL
must be sent for the database to read it and insert it correctly.
I hope I have understood and would appreciate your cooperation.
I leave the code to be a little clearer ... since the idea I had was to validate that if the serializeArray (); in the dependen_serial I take an empty value then add a null
but I would not know how to send it by ajax...
$('#form_individuo').submit(function(event)
{
event.preventDefault();
var data = $(this).serializeArray();
if(data[8].value === '')
{
var convertir_a_null = data[8].value = null;
}
else
{
$.ajax({
url: 'insert_individuo',
type: 'POST',
data: data,
})
.done(function(answer)
{
var result = $.parseJSON(answer);
if(result.answer == 'true')
{
alert("SUCCESS");
}
})
.fail(function() {
console.log("error");
});
}
});
});