When making a query through ajax, the parameters that I am sending are sent by selects but the problem is that once the query is done the values remain there and they do not want to erase me, I used the option empty()
but when I do, the options are erased and I do not want that, you could help me in this please, I leave the html and javascript code
<div class="form-group">
<select name="" id="select_granjas" class="form-control">
<option value="" selected="selected">Seleccione Granja: </option>
@foreach($granjas as $granja)
<option value="{{$granja->id}}">{{$granja->nombre_granja}}</option>
@endforeach
</select>
</div>
that foreach is by laravel, but I just need javascript to clean that select but not to erase the data inside.
var array_granjas = [];
$('#select_granjas').on('change', function(e){
array_granjas.push($(e.currentTarget).val())
console.log('value_select_prueba: --------->', array_granjas);
})
in this array
I am saving multiple values of that select and here below I call it for the ajax
$ ("# elaborar_grafica_granjas_conversion_final"). click (function () { var datachart = new Array (); var token = $ ("# token"). val (); var a_granjas = $ ("# select_granjas_conversion_final"). val (); var month = $ ("# select_granjas_mes"). val ();
var json = {
annio_granjas:a_granjas,
granjas:array_granjas,
mes:mes
}
console.log(json);
if (a_granjas == '') {
swal({
title:"No hay Fecha seleccionada.",
text:'',
type:'warning',
showCancelButton:false,
confirmButtonClass:'btn-warning',
confirmButtonText:'Corregir',
});
}else{
$.ajax({
method:'POST',
headers:{'X-CSRF-TOKEN':token},
url:'http://201.236.212.130:82/intranetcercafe/public/admin/report_destete_finalizacion_conversion_final_granjas',
data:json
}).done(function (msg){
console.log(msg);
console.log(array_granjas);
array_granjas.length=0;
})
}
})
the array farms what makes me clean the array but not the select