0
I don’t know why when I try to perform an ajax call to the url "http://localhost/meusite/controller/method" I get a 404 error saying the following "The url http://localhost/meusite/controller.html/method" was not found on the server(404). I cannot find where this "comes from. html" it is adding after the controller name, the application is running perfectly on another server.
I don’t know where the problem comes from but I will post . htaccess to see if there is an error in it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
And this is the part that makes the requisition:
var controller = 'login';
var base_url = '<?php echo base_url();?>';
function validaLogin() {
$.ajax({
'url' : base_url + controller + '/ax_validaLogin',
'type' : 'POST', //the way you want to send data to your URL
'data' : {'username': document.getElementById('username').value,
'senha' : document.getElementById('senha').value
},
'success' : function(data){ //probably this request will return anything, it'll be put in var "data"
var container = $('#errorMessage'); //jquery selector (get element by id)
if(data == "sucesso") {
window.location.href='home';
}
else {
if(data){
container.html(data);
$("#erroLogin").show();
focusLogin();
}
}
}
});
}
Remembering that I am using Codeigniter 2, PHP5.6 and Apache2 in a Linux Mint 18.
It may be valid to post the code snippet that makes the AJAX request.
– Woss
Open the file
/application/config/config.php
and post here. Maybe the itemurl_suffix
is not void.– William Novak
edited by placing the request, and checked the file config.php, url_suffix is like this:
$config['url_suffix'] = ''
– Victor Hartur de Carvalho
If you are not using static routes
base_url('controller/method')
should already be enough to call the controller and the method. This:base_url + controller + '/ax_validaLogin'
is an exaggeration of expression. And if you use the same code on another server and it does not happen, there is something wrong with the Apache rewrite configuration.– ShutUpMagda
um, I’ll check what I can on this rewrite issue, and on the base_url+controller... it’s a legacy code that I didn’t develop. Thanks for the answers.
– Victor Hartur de Carvalho
it would be good if you debug the code in firebug, I believe the problem is in the absolute path to the method, try to use the relative path, and at the end of your controller’s method use the function Exit or die to kill application, if not resolve please post firefox or Chrome debug print.
– PaulinhoCaP