Create this array which is to store addresses:
var arreglo_direcciones = [];
This arrangement, as I already mentioned, is to store addresses in another function that I have developed and it works perfectly, but when programming the main function of my form I realized that I had to validate that the addresses are required and that is where the problem comes from. , when I pass the arreglo_direcciones
empty array through ajax
it, it does not go to the side of the controller, but if this array contains elements stored there, it is passed to the controller and I can do any treatment to this array. The declaration of my main ajax function is as follows:
$('#guardar-formulario').click(function(e){
e.preventDefault();
$.ajax({
type:'POST',
url:'{{ route('regMiembros.store') }}',
data:{ arreglo_direcciones: arreglo_direcciones },
success:function(data){
if($.isEmptyObject(data.errors)){
$.smkAlert({
text: data.success,
type:'success'
});
limpiarErrores();
} else {
limpiarErrores();
$.each(data.errors, function (index, value) {
$('#_'+index).text(value);
});
$.smkAlert({
text: "Existen errores de validacion, por favor revise ",
type:'danger'
});
}
},
error: function (jqXHR, textStatus, errorThrown) {
alerta(jqXHR.responseText);
}
});
});
Try to modify the data sent in your ajax like this:
And in the validator or validation rules of your controller verify that the value is required, it should work.
Check this post POST in the answer they explain well why jquery does not pass the empty array.
Hello, the way that occurs to me is that in your controller you place an isset as in the following code:
Or you can also validate it from the ajax side, verifying that your array is not empty. Hope it has been helpful.
First try to capture the possible scenarios and then you will know which path the execution thread takes...
I hope it works for you Bro... ReNiceCode...