Welcome Guest, Not a member yet? Register   Sign In
JQuery and paging (JQuery question)
#11

[eluser]xwero[/eluser]
Because you are so persistent i've took it upon me to get a working example.

master view file
Code:
<html>
    <head>
        <script src="jquery.js"></script>
        <script>
            $(function(){
                init();
            });
            
            init = function ()
            {
                $('p.paging a').click(function(){
                    var offset = $(this).attr('href');
                    offset = offset.substring(offset.lastIndexOf('/')+1);
                    $.ajax({
                        url: '../ajaxpaging/'+offset,
                        type: 'GET',
                        timeout: 1000,
                        error: function(){
                            alert('Error loading document');
                        },
                        success: function(html){
                            $('body').html(html);
                            init;
                        }
                    });
                    return false;
                });
            }
        </script>
    </head>
    <body>
      <?=$content; ?>
    </body>
</html>
The init is a lambda function so after the ajax request you have the same behavoir

pagepart view file
Code:
<p class="paging">&lt;?=$this->pagination->create_links(); ?&gt;</p>

controller
Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }

function jqpaging()
    {
        $this->load->library('pagination');
        $this->load->helper('url');

        $config['base_url'] = site_url().'/welcome/jqpaging/';
        $config['total_rows'] = 25;
        $config['per_page'] = 5;
        
        $this->pagination->initialize($config);
        $data['base_url'] = site_url().'/welcome/jqpaging/';
        $data['total_rows'] = 25;
        $data['per_page'] = 5;
        $data['content'] = $this->load->view('jqpagcontent','',true);
        $this->load->view('jqpaging',$data);
    }
    
    function ajaxpaging()
    {
        $this->load->library('pagination');
        $this->load->helper('url');
        
        $config['base_url'] = site_url().'/welcome/jqpaging/';
        $config['total_rows'] = 25;
        $config['per_page'] = 5;
        $this->pagination->initialize($config);
        
        $return = $this->load->view('jqpagcontent','',true);
        echo $return;
    }
}

This only takes care of the paging, you have to add the actual content yourself.

It's a bit easier than i thought.
#12

[eluser]worchyld[/eluser]
Hey xwero, thank you for your answer, I'll take a look at it and post issues later. Adding content, etc shouldn't be an issue.

The reason I'm being persistent on this is because in the past sometimes I've found I'm posting a thread and no-one ever replies, or there'll be cryptic messages that don't answer the question. Sometimes I feel like just quitting CI because of the poor community -- but I still with it, because I find CI easier to understand that Cake, or just coding from scratch.

Also, I feel a real-working example of integration of CI with JQuery (without plugins) is important to anyone who wants to see how CI/JQuery actually work.
#13

[eluser]xwero[/eluser]
I think it depends on the people and how they feel. Sometimes cryptic messages make sense in the posters mind. I don't apologise for others but i think like in every community there are people who really want to help out others and people that mock others.

I try to help someone to the best of my knowledge. I don't have all the answers and sometimes i'm just plain wrong.

For me the ways to look at a problem are more important than the solution itself that's why i like the CI community. There are new users, even new php users, and php veterans and everything in between. Each of them have their own way of doing things.

but i'm rambling here Smile

I think the integration of jQuery/prototype/dojo/YUI with CI depends on the will of the developer to keep javascript/ajax and php separate. I requires more effort that an ajax wrapper like xajax. I don't know enough about it to say it's a bad thing but my main concern with javascript wrappers is the functionality of the site without javascript and security.
#14

[eluser]worchyld[/eluser]
I'm almost there, but when I click on the link (now ajaxed) it produces;

"ob_start() [<a href='ref.outcontrol'>ref.outcontrol</a>]: Cannot use output buffering in output buffering display handlers in C:\Program Files\xampp\htdocs\codeignitor\system\libraries\Exceptions.php on line 160"

I've removed all custom view libraries (as found per wiki), but it still displays the error. I'm going to look at a simple JQuery output in CI to see if this can help.

EDIT:

I've found out that the reason why this message comes up is because your outputting right inside your controller.

So, I went back to a very simple JQuery HTML loading example in CI. Note that this works!

So hopefully I can apply the idea to my above question;

The HEAD;
Code:
&lt;base href="&lt;?=base_url()?&gt;" /&gt;
    <scr+ipt type="text/javascript" src="assets/javascript/jquery.js"></scr+ipt>

    <scri+pt type="text/javascript">
    /* &lt;![CDATA[ */

        $(document).ready(function() {    
            
            $("a#generate").click(function() {                
                var href = $(this).attr('href');
                // alert(href);

                $('p.surprise').hide().load(href, function() {
                    $(this).addClass("ohmy").show("slow");
                });
            
                return false;
            });
    
        });

    /* ]]> */
    </scr+ipt>

    &lt;style type="text/css"&gt;
        p.surprise {
            display: none;
            margin-bottom: 5px;
        }
        p.ohmy{
            padding:5px;
            border:1px solid #acd373;
            background:#fafff3;
            margin-bottom: 10px;
        }
    &lt;/style&gt;

// The BODY
Code:
<a id="generate" href="index.php/message_slideshow/get_message/">Run</a>
<p class="surprise">
</p>

// The CONTROLLER
Code:
class Message_slideshow extends Controller {

    function Message_slideshow() {
        parent::Controller();        
        $this->load->library('view');
        // $this->output->enable_profiler(TRUE);
    }

    function index() {      
        $this->view->load("message_slideshow");
    }

    function get_message() {
        $this->view->load("jquery_message");
    }

} // end class

// JQuery Message (VIEW)
Code:
Congratulations! You just ran a snippet of jQuery code. Wasn't that easy?
#15

[eluser]xwero[/eluser]
it has probably to do with some custom made gzip fuction that doesn't work well on your server




Theme © iAndrew 2016 - Forum software by © MyBB