SOLUTION: One of the given solutions (which was the one that worked for me was to eliminate dataType : 'json',
then if the route remains as in my case /search/search/undefined
that I solved changing window.location.href = response.redirect;
per window.location.href = '';
.
I have the following code in which I first obtain in an array the selected checkboxes to then make a Post of said data that all it does is change the state in the database, that is, the default fields are found in the database with the value "Active" and the idea is that after having selected several of them in the form and clicking on the "Archive" button the status of the fields in the database change to "Archived" what I do not know is why the function never enters Success, always gives an error and triggers the "Does not work" alert but if I reload the page or go to the bd the value of the fields changed successfully, does anyone know what can be owed that? thanks in advance.
CODE OF FORM FOR THE PART OF THE CHECKBOX:
<ul id='listResult'>
<?php for($i=0;$i<count(1);$i++)
{
?>
<li><input id ='opt'type='checkbox' name='opt' value='<?= $dato['id']?>'><?= $dato['desc'].' - '.$dato['date'].' - '.$dato['status']?></li>
<?php
}
?>
</ul>
CODE PART OF THE AJAX:
function archivar()
{
var busquedas = [];
$('#listResult input[type=checkbox]:checked').each(function()
{
busquedas.push($(this).attr('value'));
});
if(busquedas.length>0)
{
$.ajax({
url : 'search/search',
data : {opt:busquedas},
type : 'POST',
dataType : 'json',
success : function(response){
window.location.href = response.redirect;
alert("funciona");
},
error: function(error){
alert("No funciona");
}
});
}
}