【问题标题】:load pages dynamically using jQuery $.post in codeigniter在 codeigniter 中使用 jQuery $.post 动态加载页面
【发布时间】:2012-12-03 15:27:55
【问题描述】:

我有一个主页,其中有两个 DIV(左和右)。 在左 div 我将有一些项目。并在正确的 div 中显示其详细信息。 (请看图)

在这里,单击左侧 div 中的项目,应加载其相应的详细信息。 我对两个 div 有两个单独的视图。我可以从控制器功能加载左视图。

但我应该根据左侧 div 项的item_id 加载右侧 div,而不需要任何页面刷新。

为此,我将通过 jQuery $.post 发送 item_id 并获取 details_page

我对详情页的看法是这样的

<div class="title"><?php echo $title; ?></div>
<div class="details">
    <div class="author"><?php echo $author; ?></div>
    <div class="pagedata"><?php echo $pagedata; ?></div>
</div>

这些 PHP 变量应该在加载详细信息页面时被替换。

请帮助我在 codeigniter 中使用 jQuery 对上述场景进行编码。

【问题讨论】:

  • 让您的生活更简单并使用 jquery 垂直标签 我看不出这里需要 AJAX 的任何原因。使用适当的工具。

标签: php jquery codeigniter


【解决方案1】:

在您的 PHP 控制器中,您需要一个为视图提供服务的方法:

class Foo extends CI_Controller {
    public function getItem($item) {
        // the view holds the html for the right div
        $this->load->view($item);
    }   
}

在 jquery 中,您可以像这样获取视图:

$.get('example.com/foo/getItem/item1', function(resp){
    $('#contentDiv').html(resp);
}, 'html'); 

当然,每次单击左侧 div 上的窗格并使用适当的项目名称时,您都会调用此 jquery 代码 sn-p。

【讨论】:

    猜你喜欢
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多