【发布时间】:2013-08-03 18:05:02
【问题描述】:
我正在使用 CodeIgniter 开发一个项目,但是在使用 jQuery 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 page not found 错误。
【问题讨论】:
-
你把你的ajax代码放在哪里了。在什么文件里??
-
我通常只是这样做:
url : '/test/login_with'并且总是有效。
标签: .htaccess codeigniter jquery controller