Alternative implementation method of parsing CI's AJAX paging_PHP tutorial

WBOY
Release: 2016-07-21 15:02:50
Original
947 people have browsed it

I took a look at CI's paging class and there is no content about AJAX. I also saw pagination class extensions written by several other experts on the forum. I feel that it is actually unnecessary.
It can still be achieved by making some small changes on the existing basis.
Let’s get to the point:
CI’s native paging class has a parameter $config[anchor_class]
This parameter is used to set the style of paging links. , so we can set it like this:
$config[anchor_class] = "class=ajax_fpage";
Then in the view part, we use the method of disabling the default action of a sticky note to obtain the AJAX call Get the effect.
The code is as follows:

Copy the code The code is as follows:

<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>

When When ajax_fpage is clicked, it disables the default action of the a tag and obtains the href information. Then it uses the get method to obtain the href content and updates the dom.

Such a complete ajax paging is realized. There is no need to extend the original class.
The detailed PHP code is as follows:
Copy code The code is as follows:

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] = ;
$config[next_tag_open] =
  • ;
    $config[next_tag_close] =
  • ;
    $config[prev_link] = ;
    $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.htmlTechArticleI looked at the paging class of CI and there is no content about AJAX. I also saw several others on the forum. The paging extension written by the master feels that it is actually unnecessary. Made something based on the existing ones...
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!