我正在开发一个CodeIgniter的项目,但我用jQuery AJAX发送请求时出现问题。我的默认控制器是:我得到'页面未找到'与Codeigniter和AJAX请求错误
$route['default_controller'] = "test";
,这里是我的测试控制器:
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class test extends CI_Controller {
function __construct() {
parent::__construct();
}
public function login_with() {
echo "1";
}
}
,这里是我的AJAX请求:
$(function() {
$('#login_with').click(function() {
$.ajax({
type: "post",
url: "<?= base_url('test/login_with') ?>",
data:"login=1",
success:function(ajax_success){
alert(ajax_success);
}
});
});
});
终于在这里是我的.htaccess文件:
DirectoryIndex index.php
RewriteEngine on
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
这里有什么问题?请求发送时,我收到404页未找到错误。
你在哪里把你的Ajax代码。在什么文件? – SasaT
我通常只是这样做:'url:'/ test/login_with''并始终有效。 – SasaT