Galera I have a search field for ajax in laravel that works normally local but on the server it is returning error. When the search route (post -> link ) is triggered by the keyup event of error 301 Moved Permanently and then again (mysteriously) another route (get - > link ) that consequently returns error 404 not found because this second route does not really exist.
This error only occurs through ajax, when I enter and the form is sent in a conventional way the route is found and the results are displayed correctly.
Has anyone had problems like this? Can anyone tell me if this is a problem in the codes or some server configuration?
This is the route that is in routes.php
Route::post('/prefeitura/search', 'Admin\PrefeituraController@search');
This is the .htaccess that is in the laravel root folder (files in the public folder have also been moved to the laravel root folder)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This is the ajax function that does the search and displays the found data
$("#searchPrefeitura").on('keyup',function(){
$.ajax({
url: 'http://site.com.br/cidadedigital/admin/prefeitura/search/',
type: 'POST',
dataType : 'html',
encode : true,
data :{exp:$(this).val(), _token: $("#_tokenSearch").val()},
beforeSend : function(){
$(".spinner").removeClass('hide');
},
success : function(data){
$("#listPrefeitura").html(data);
},
complete : function(){
$(".spinner").addClass('hide');
$("#limpabusca").fadeIn();
},
error : function(data)
{
//console.log(data.responseText);
}
});
});