Welcome Guest, Not a member yet? Register   Sign In
Is it really Ajax what I am looking for ? Can you check this code?
#1

[eluser]ytsejam[/eluser]
Hello ,
I am a newbie developer. This is the first time I try to use Ajax. When you start the webpage, a loading animation starts and navigation and content part divides into left and right sides. When I click navigation links I only want content part to change.
MY_Controller.php:
Code:
function render_page($view) {
    if( ! $this->input->is_ajax_request() )
    {
      //do this to don't repeat in all controllers...
      $this->load->view('templates/header', $this->data);
      //menu_data must contain the structure of the menu...
      //you can populate it from database or helper
    }

    $this->load->view($view, $this->data);

    if( ! $this->input->is_ajax_request() )
    {
     $this->load->view('templates/menu');
     $this->load->view('templates/footer', $this->data);
    }

About controller
Code:
public function view($page = 'about')
        {
         $this->load->helper('text');
            $this->data['records']= $this->about_model->getAll();
            if ( ! file_exists('application/views/pages/'.$page.'.php'))
            {
                // Whoops, we don't have a page for that!
                show_404();
            }

            $data['title'] = ucfirst($page); // Capitalize the first letter


            $this->render_page('pages/'.$page,$data);


        }

Ajax.js file is inside head part of header.php. But still I need to change url part by the menu selection not the only about.php.

Code:
$("#sidebar-content ul li a").click( function(){

        $.ajax({
                    url: "<?php echo site_url('about'); ?>",
                    type: 'POST';
                    data: JSON,
                    success: function(response) {
      $('#content').html(response.msg);
                    }
                });
                });

        return false;
});

my menu is

Code:
<div id="sidebar-content">
<ul id="menu">
<li class="current"><a href="&lt;?php echo site_url('home'); ?&gt;">ANASAYFA</a></li>
<li><a href="&lt;?php echo site_url('about'); ?&gt;">HAKKIMIZDA</a></li>
.
.
.
</div>

How can I make ajax to work with every menu item (home/about)? What is your suggestion about to post partials to content div?


Messages In This Thread
Is it really Ajax what I am looking for ? Can you check this code? - by El Forum - 08-04-2012, 11:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB