在CodeIgniter中添加了静态页面,并且使用Ajax进行Controller调用会产生404页面未找到错误。只有几小时的CI经验。
感觉这是站点配置出现问题或缺少某些路由,而不是控制器名称。不知道哪种设置可能会导致问题。
也许可以通过使用Ajax的替代方法或使用CI帮助程序来解决临时问题吗?
[web/content/application/views/frontend/static/page1.php]
<script>
function f1() {
$.ajax({ type: 'POST', url: '<?= site_url("Controller1/method2"); ?>' });
$.ajax({ type: 'POST', url: '<?= site_url("index.php/Controller1/method2"); ?>' });
}
</script>
[web/content/application/controllers/Controller1.php]
class Controller1 extends MY_Controller {
public function method1($page) { if ($page == "page1") $this->load->helper('url'); }
public function method2() { echo '<script>alert("called");</script>'; }
}
[routes.php]
$route['404_override'] = 'admin/error';
$route['ajax/(:any)'] = "ajax/$1";
$route['(page1)'] = "Controller1/method1/$1";
[.htaccess]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
[config.php]
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';