• 0

Codeigniter pagination with jQuery


Question

Hey guys, I have been stuck on this problem for days and am about the crack... I have no idea what im doing wrong or where i should look for help.

I have been using the following ajax pagination library.

The search page allows users to filter the results by a number of categories.

This is the search view:

<form method="post" id="search_form" name="search_form">
 <div id='sidebar_wrapper'>
  <div id='sidebar'>
   <div class="slider_header">
    Country
   </div>
   <div class="slider_content">
    <select id="country_dropdown" name="country_dropdown">
        <option value='1' >Country 1</option>
        <option value='2' >Country 2</option>
    </select>
   </div>
   <div class="slider_header">
    Region
   </div>
   <div class="slider_content">
    <select id='region_dropdown' name='region_dropdown'>
        <option value='1' >Region 1</option>
        <option value='2' >Region 2</option>
    </select>
   </div>
   <input id='profile_search_button' type='button' value='Search'></input>
  </div>
  <div id='sidebar_content'>
   <div id='content_header'>
    Search
   <div id='search_results'></div>
  </div>
  <div id='sidebar_footer'></div>
 </div>
</form>

So when the "profile_search_button" is clicked the following jQuery code is run:

$("#profile_search_button").click(function()
{
    $('#search_results').hide();

    $.post("http://localhost/index.php/search/search_database", { "serialised_form" : serialize_form() },
    function(data)
    {
        $('#search_results').html(data);
        $('#search_results').slideDown('slow');
    });
 });

function serialize_form()
{
    return $('#search_form').serialize();
}

That function calls the following PHP function from the search controller:

public function search_database()
{
    echo $this->input->post('serialised_form');

    $this->load->library('Jquery_pagination');

    $config['base_url'] = site_url('search/search_database');
    $config['total_rows'] = 100;
    $config['per_page'] = '10';
    $config['div'] = '#search_results';
    $config['additional_param']  = 'serialize_form()';

    $this->jquery_pagination->initialize($config);
    echo $this->jquery_pagination->create_links();
}

Ok, so I can pass the form data to the PHP function the first time it is called - I can echo out the serialised data (I'll look into parsing that information at a later stage). The problem seems to be when a pagination link is clicked. The same PHP search function is called again but the form data is not sent with to the page...

The author also says that I should add the following to the config file:

$config['additional_param']  = 'serialize_form()';

Ive done that, and added the necessary javascript to the view to serialize the form data

<script type="text/javascript">
    function serialize_form() {
        return $('#search_form').serialize();
    }
</script>

Apparently I should "receive filtering datas as POST in your pagination function".

But how do i access this form data... Ive tried to read the POST and GET values but they wont work.

This is the example i have been working on: http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline

Doesn't seem to be much more info out there... can anyone help?

Hope this makes sense...

Link to comment
https://www.neowin.net/forum/topic/958374-codeigniter-pagination-with-jquery/
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Got it working guys. Just a few silly mistakes.

Had to serialise the form data instead of sending it as a JSON object

$("#profile_search_button").click(function()
{
    $('#search_results').hide();

    $.post("http://localhost/index.php/search/search_database",  serialize_form(),
    function(data)
    {
        $('#search_results').html(data);
        $('#search_results').slideDown('slow');
    });
 });

And turns out that the 'additional_param' was working after all.

Uhh... time for bed I think :laugh:

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked] "{e2bf9676-5f8f-435c-97eb-11607a5bedf7}"="Share" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Blocked] "{e2bf9676-5f8f-435c-97eb-11607a5bedf7}"="Share" [-HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\ModernSharing] Remove that Share text.
    • Meh could never use the UWP as I use WhatsApp business and it's features are available on the standard. Thos this applies to both windows and macos+ipad versions. So I'm stuck on using web versions for whatever platform.
    • I hardly have issues with my ipad pro 4's faceid while holding it on Portrait
    • Sure, one example: Two computers side by side. Your main system is connected to a sound bar or a high end TV with good audio built in. Your secondary machine is the one you play music, movies, YouTube, check email, etc. on another monitor while you work/play games on your main system. In this case, the main computer converts all audio to Dolby Atmos which goes out to the main TV/soundbar (or your bluetooth/headphones), no matter if it comes from the main machine or the secondary...with no latency issues. And whatever you'd be doing on the secondary computer isn't hitting your main computer's CPU or GPU if, say, gaming some serious FPS or at 4k etc. That's just one home use case for a networked audio solution. I'm sure others can think up more of them.
    • Yeah, I've looked at all of these. Dante is a pro and expensive program, of course. I'm just looking for simple audio/music sharing from one PC/device to another. Voicemeeter is a lovely bit of kit, but the interface is NOT user friendly to set up initially, unless you are an audio engineer who thinks the way the program does. It works though. I just didn't feel the juice was worth the squeeze on that one. The other ones you mention each have problems, like no longer maintained/updated, blocks auto-audio switching on receiving computer from say headphones to HDMI, etc. Spotify does this, but only for music played by Spotify. Multiplicity does this (but isn't free) for all audio on one PC (like you'd want) but hiccups the audio on the source PC if too much CPU is used (so you really can't use a very old PC as a music/video/youtube player). Oh, and because of how the old version (I haven't tried the newly released one because it still has a showstopping bug that's not been addressed) shares the mouse between screens, it interferes (and can crash) video games on the server/main machines, etc. Multiplicity Pro was the best of the normal solutions, however. If the two machines are side by side, you can use analog line out to analog line in, but then you are getting analog noise/problems. It's the simplest and most solution, of course.
  • Recent Achievements

    • Rookie
      Snake Doc went up a rank
      Rookie
    • First Post
      nobody9 earned a badge
      First Post
    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      496
    2. 2
      Michael Scrip
      205
    3. 3
      ATLien_0
      201
    4. 4
      Xenon
      136
    5. 5
      +FloatingFatMan
      117
  • Tell a friend

    Love Neowin? Tell a friend!