Send data to a view with out reloading content?

#1
[eluser]sico87[/eluser]
I am creating a site where users can upload there own background images, after upload they see each background they uploaded in a menu represented by a number, clicking on the number will in theory load in the new background, however I have noticed that does this calls in the view again as well (the view is already loaded from another function, is there a ways I can pass the data to the view without loading the view, can I do it with ajax? if so how?

My code currently

Code:
public function set_background() {
        $this->load->model('image_model');
        if($query = $this->image_model->get_background_by_id($this->uri->segments[3])) {
            if($query) {
                $data['new_background'] = $query;
            }
        }
        $this->load->view('template/background-select', $data);
    }

My Model:

Code:
public function get_background_by_id($background_id) {
    $this->db->select('background_name');
    $this->db->from('background');
    $this->db->where('background_id', $background_id);

    $query = $this->db->get();
    return $query->result_array();
}

My View

<div id="background-select">


Code:
&lt;?php
        $count = 0;
            if(isset($special)) {
                foreach ($special as $row) {
                    $count ++;
                    print '<div class="select">';
                        print "<a class='background_btn' href='index.php/home/set_background/".$row['>$count</a>";
                    print '</div>';
                    if($count == 1) {
                        $background = $row['background_name'];
                    }

                }
            }
            if(isset($generic)) {
                foreach ($generic as $row) {    
                    $count ++;
                    print '<div class="select">';
                        print "<a class='background_btn' href='index.php/home/set_background/".$row['>$count</a>";
                    print '</div>';
                    if($count == 1) {
                        $background = $row['background_name'];
                    }

                }
            }
            if(isset($user_background)) {
                foreach ($user_background as $row) {
                $count ++;
                    print '<div class="select">';
                        print "<a class='background_btn' href='index.php/home/set_background/".$row['>$count</a>";
                    print '</div>';
                    if($count == 1) {
                        $background = $row['background_name'];
                    }

                }
            }
        ?&gt;
    </div>
    <div id="wrapper" style=&lt;?php echo"background:url(/media/uploads/backgrounds/".$background.");";?&gt;>

The view gets loaded in originally here

Code:
public function index() {
    //  $this->output->enable_profiler(TRUE);
        $data = array();
        if($query = $this->category_model->get_all_online()) {
            $data['main_menu'] = $query;
        }
        $this->load->model('image_model');
        /*
        * Sort out the users backgrounds, basically do a check to see if there is a 'special' background
        * if there is not a 'special' background then IF the user is logged in and has a background of there
        * own show that one, if not show a generic one, if they are not logged in show a bang one
        */
        $image = array();
        if ($query = $this->image_model->get_special_backgrounds()) {
            $image['special'] = $query;
        } elseif(!isset($image['special']) && !isset($this->session->userdata['user_id'])) {
            if($query = $this->image_model->get_bang_background()) {
                $image['generic'] = $query;
            }
        }

        if(isset($this->session->userdata['user_id'])) {
            if($query = $this->image_model->get_user_backgrounds($this->session->userdata['user_id'])) {
                $image['user_background'] = $query;
            }
        }
        $data = array_merge($data, $image);
        $this->load->view('home/main_page.php', array_merge($data, $image));
    }

Hope someone can help thanks

#2
[eluser]stuffradio[/eluser]
I'm not sure how to do the get part yet, but you can use JQuery and use the get parameter instead of post. This website helped me with part of my JQuery questions.

http://frinity.blogspot.com/2008/06/chan...query.html

I know there are people here who are way better at AJAX than I am, so maybe they can tell you how to do the GET part.

You can also google it: http://lmgtfy.com/?q=Ajax+GET


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.