甚至我还添加了"if (!define ('BASEPATH')) exit('不允许直接脚本访问');实际上我需要在div中显示数据我的ajax调用:下面是ajax调用调用Createcaptcha获取数据,但不是数据它响应"No direct script access allowed"
$(document).ready(function(){
$.ajax({
type: "POST",
url: 'website/Createcaptcha',
success: function(data){
$("#captcha").html(data);
}
});
});
下面是控制器
public function Createcaptcha(){
$image = $this->captcha_model->create_image();
echo $image;
}
响应数据在div中显示为"No direct script access allowed"它在xampp localhost
检查是否在codeigniter中设置了BASEPATH。它设置在根目录的index.php中。只需回显BASEPATH并查看打印的内容。
在index.php
中查找以下内容define('BASEPATH', str_replace("''", "/", $system_path));
我将<?
替换为<?php
,由于服务器中的php设置,一切工作正常。
请使用
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
database.php文件
我也遇到过类似的问题,对于那些可能想要解决这个问题的人,我的十美分。
在basepath网站名称设置为https://www.websitename.com和客户端打开没有https (http://www.websitename.com),也在某些情况下没有www (https://websitename.com或http://websitename.com)。
由于它们中的任何一个都与定义的基路径不匹配,因此请求不会被视为ajax请求。解决方案:确保你有正确的重定向(http到https &从非www到www)。
https,WWW重定向答案链接
在我的案例中,项目路径(基础URL)是错误的。