【发布时间】:2019-10-06 05:20:58
【问题描述】:
第一次尝试使用 CI,使用 Ajax 调用方法时出现“找不到页面”错误。仔细检查了名字,现在刚刚在海上迷路了。
[page_a.php]
<script>
function f1() {
$.ajax({
type: 'POST',
url: '<?= site_url("controller_a/method_a") ?>',
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status == 0 ) msg = 'Not connected, verify network [000]';
else if (jqXHR.status == 404 ) msg = 'Requested page not found [404]';
else if (jqXHR.status == 500 ) msg = 'Internal server error [500]';
else if (exception == 'parsererror') msg = 'Requested JSON parse failed';
else if (exception == 'timeout' ) msg = 'Time out error';
else if (exception == 'abort' ) msg = 'Ajax request aborted';
else msg = jqXHR.responseText;
alert(msg);
}});}
</script>
[controller_a.php]
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class controller_a extends MY_Controller {
public function method_a() {
echo '<script>alert(":-)");</script>';
}}
【问题讨论】:
-
许多可能性..您的控制器真的扩展了自定义基本控制器吗?如果没有,您应该改为扩展 CI_Controller。另外,请记住控制器的文件名和类名都必须以大写字母开头(因此
class Controller_a extends MY_Controller和 Controller_a.php 将是适当的名称) -
谢谢,改成扩展CI_Controller,使用大写,还是一样的错误。
-
在你的 url 中包含 index.php 如果你没有配置 index.php,打开 google chrome 控制台并显示请求的去向,显示整个 url,访问 url 并检查有什么问题.
标签: codeigniter http-status-code-404