我以CI開始,我需要一些幫助。我試圖用Ajax加載一些html頁面,這個html文件存儲在視圖文件夾中,我試圖使用控制器訪問這些文件,直到現在我還沒有成功。我想知道,我如何訪問這些文件,並且如果我使用的控制器是正確的,或者有更好的方法來完成此操作。CodeIgniter中的鏈接,控制器
控制器
class Router extends CI_Controller
{
public function index($file)
{
$this->load->view($file);
}
}
阿賈克斯
var SampleFunction = function (router) {//router is my base_url() + '/router'
var pageContentBody = $('.page-content .page-content-body');
if ($("#startLoadTag")){
$.ajax({
type: "post",
cache: false,
url: router + '/SampleLink.html',
dataType: "html",
success: function (html) {
pageContentBody.html(html);
}
});
}
}
到現在爲止我只得到404未找到。
不知道你是否有有apache配置爲刪除索引,但如果不是,你應該擊中路由器+'/index/SampleLink.html' – Rooster
無法將參數傳遞給codeigniter中的'function index()'。將''作爲方法路由。最簡單的就是創建另一個函數並在你的ajax路徑中使用它 – charlietfl
好的,我修復了這些bug。但是現在我對系統有一個很大的安全漏洞。如果我在Chrome上更改HTML鏈接名稱並單擊鏈接,則會加載該文件。有任何阻止更改鏈接名稱或東西來增加安全性。你的建議是什麼? – user3108967