Heim  >  Artikel  >  Backend-Entwicklung  >  解析CI的AJAX分页 另类实现方法_PHP教程

解析CI的AJAX分页 另类实现方法_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:02:50949Durchsuche

看了一下CI的分页类没有写到关于AJAX的内容,也在论坛上看到其他几位大神写的分页类扩展,感觉其实是没有必要。
在现有的基础上做了一下小小的改动还是能实现的。
下面进入正题:
CI的原生分页类中有一个参数 $config[anchor_class]
这个参数是用来设置分页链接的样式的,所以我们可以设置成这样:
$config[anchor_class] = "class=ajax_fpage";
然后在view部分这样采用禁止a便签默认动作的方法来取得AJAX的调取效果。
代码如下:

复制代码 代码如下:

<script><BR> $(.ajax_fpage).click(function(e){<BR> var url = $(this).attr(href);<BR> $.get(url,{},function(res){<BR> $(#show_what_table).html(res);<BR> });<BR> event.preventDefault();<BR> });<BR></script>

当ajax_fpage点击的时候,禁止a标签的默认动作,并得到href信息,然后用get方法取得href的内容,并更新dom.

这样一个完整的ajax分页就实现了。从而不需要对原始的类进行扩展了。
详细的PHP代码如下:
复制代码 代码如下:

function ContentList($id,$p=0)
{
    $this->load->library(pagination);
    $config[base_url] = site_url(qyadmin/ContentList/.$id./.$p);
    $config[total_rows] = $this->admin->content_list($id,$p,1);
    $config[per_page] = 5;
    $config[uri_segment] = 5;
    $config[first_link] = FALSE;
    $config[last_link] = FALSE;
    $config[full_tag_open] =

;
    $config[full_tag_close] =

;
    $config[display_pages] = FALSE;
    $this->load->helper(url);
    $skin_url = base_url().APPPATH . "views/templates";
    $config[next_link] = 解析CI的AJAX分页 另类实现方法_PHP教程;
    $config[next_tag_open] =
  • ;
        $config[next_tag_close] =
  • ;
        $config[prev_link] = 解析CI的AJAX分页 另类实现方法_PHP教程;
        $config[prev_tag_open] =
  • ;
        $config[prev_tag_close] =
  • ;
        $config[anchor_class] = class="ajax_fpage";
        $this->pagination->initialize($config);
        $content = $this->admin->content_list($id,$p,0,$config[per_page],$this->uri->segment(5));
        $fpage = $this->pagination->create_links();
        $this->smarty->assign(fpage,$fpage);
        $this->smarty->assign(content,$content);
        $this->smarty->view(show.tpl);
    }

    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327887.htmlTechArticle看了一下CI的分页类没有写到关于AJAX的内容,也在论坛上看到其他几位大神写的分页类扩展,感觉其实是没有必要。 在现有的基础上做了一...
    Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn