php - Codeigniter - 无法点击类中的方法

标签 php jquery ajax codeigniter

这是我的第一个 CI 项目,请原谅。

我根本无法通过 AJAX 调用访问方法。它不断在 Web Inspector 中显示为 404。

我有一个名为“home.php”的 Controller 。它的工作。我可以登陆我的主页。

然后我在悬停事件上触发这个 AJAX 调用

function showDataWindow(){
    // i might switch this to data attr, but for now item IDs are contained in class
    var thisClass = $(this).attr('class');
    var thisIDpos = thisClass.indexOf("id-")+3;
    var thisID = thisClass.substr(thisIDpos, 3);
    alert(thisID); // alerting correctly
    $.post('getMoreInfo', { ID: thisID},
        function(data) {
             .. act on data

我可以简单地找到我正在调用的方法 - getMoreInfo。总是 404。

我的 Controller 中有一个 home.php 类并将其设置为我的默认值,它可以正常工作,因为我正在登陆我的主页并获取索引。但是在那个家庭 Controller 中也是我的 getMoreInfo 功能......

public function getMoreInfo()
{
    $ID = $_POST['ID'];
    $this->load->model('Artist_model');
    $assocReturned = $this->Artist_model->get_more_info($ID);
    echo json_encode($assocReturned);
} 

而且我觉得有一个微型 MC Hammer 保护着这个功能。 “你不能碰这个”。他 mock 我穿着他的小降落伞裤和微小的褪色。

我认为这一定是我在 Jquery AJAX 帖子中处理 URI 的方式?我在我的 htaccess 中重写了索引(我对此有点模糊)

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]

但我已经尝试了 AJAX 调用中的几乎所有 URI 排列

www.mySite.com/index.php/home/getMoreInfo
index.php/home/getMoreInfo
index.php/getMoreInfo
/home/getMoreInfo
home/getMoreInfo
/getMoreInfo
getMoreInfo

!

没有一个有效。

最佳答案

你必须调用什么取决于你的路由器是如何配置的。

默认调用为 /home/getMoreInfo,但如果您重新配置了路由器,则可以更改。引用:http://codeigniter.com/user_guide/general/routing.html

关于php - Codeigniter - 无法点击类中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12571406/

相关文章:

php - 在 Prestashop 1.7 的管理产品页面中添加新字段的正确方法

javascript - 如何动态创建按钮并为html页面添加onclick事件

javascript - 在前一个子 div 的 jquery 之前添加一个新的子 div

javascript - 如何通过ajax调用导航到跨域网页?

php - mysql 哪里来自一个数组 json

php - PHP 连接 MYSQL 出错

php - 从 CronJob 启动时,Unix .sh 文件工作不正确

javascript - 如果陈述属实,请提交表格

javascript - 关闭弹出窗口

javascript - 根据属性显示 html