jquery
  • codeigniter
  • pagination
  • 2010-12-04 98 views 2 likes 
    2

    我一直在這個問題上困擾了好幾天,並且我對這個問題很擔心......我不知道我在做什麼錯,或者我應該尋找幫助。Codeigniter與jQuery分頁

    我有一個搜索頁面,允許用戶篩選一些類別的結果。

    這是視圖:

    <form method="post" id="search_form" name="search_form"> 
    <input type='hidden' id='seeking_gender_id' value='<?php echo $profile->gender_id ?>'/> 
    
    <div id='sidebar_wrapper'> 
        <div id='sidebar'> 
        <div class="slider_header"> 
        Country 
        </div> 
        <div class="slider_content"> 
        <select id="country_dropdown" name="country_dropdown"> 
        <?php 
        if($countries->num_rows() > 0) 
        { 
         foreach($countries->result() as $row) 
         { 
         $selected = ($row->country_id == $profile->country_id ? "selected='yes'" : ""); 
         echo "<option value='" . $row->country_id . "' " . $selected . ">" . $row->country ."</option>"; 
         } 
        } 
        ?> 
        </select> 
        </div> 
        <div class="slider_header"> 
        Region 
        </div> 
        <div class="slider_content"> 
        <select id='region_dropdown' name='region_dropdown'> 
        <option value="0">All regions</option> 
        <?php 
         if($regions->num_rows() > 0) 
         { 
         foreach($regions->result() as $row) 
         { 
         $selected = ($row->region_id == $profile->region_id ? "selected='yes'" : ""); 
         echo "<option value='" . $row->region_id . "' " . $selected . ">" . $row->region ."</option>"; 
         } 
         } 
        ?> 
        </select> 
        </div> 
        <div class="slider_header"> 
        Gender 
        </div> 
        <div class="slider_content"> 
        <?php 
        $male_checked = ($profile->seeking_gender_id == 1 ? "checked='yes'" : ""); 
        $female_checked = ($profile->seeking_gender_id == 2 ? "checked='yes'" : ""); 
        ?> 
        <input id='male_checkbox' type="checkbox" name="genders" <?php echo $male_checked ?> value="1" /> 
        Male 
        <br/> 
        <input id='female_checkbox' type="checkbox" name="genders" <?php echo $female_checked ?> value="2" /> 
        Female 
        </div> 
        <div class="slider_header"> 
        Age 
        </div> 
        <div class="slider_content"> 
        Between 
        <input id="min_age" type="text" maxlength="2" style="width: 35px" value='<?php echo $profile->min_age ?>'/> 
        and 
        <input id="max_age" type="text" maxlength="2" style="width: 35px" value='<?php echo $profile->max_age ?>'/> 
        </div> 
        <input id='profile_search_button' type='button' value='Search'></input> 
        </div> 
        <div id='sidebar_content'> 
        <div id='content_header'> 
        Search 
        <div id='profiles_found' style='float: right'>0</div> 
        </div> 
        <div id='search_results'></div> 
        </div> 
        <div id='sidebar_footer'></div> 
    </div> 
    </form> 
    

    所以,當點擊 「profile_search_button」 的時候,下面的jQuery代碼運行:

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

    該函數調用下面的PHP函數:

    public function search_database() 
    { 
    // HOW AM I MEANT TO GET THE VALUES OF THE FORM FILTERS? eg: country_id, region_id etc 
    
    $this->load->library('Jquery_pagination'); 
    
    $config['base_url'] = site_url('search/blahh/'); 
    $config['total_rows'] = 100; 
    $config['per_page'] = '10'; 
    $config['div'] = '#search_results'; 
    
    $this->jquery_pagination->initialize($config); 
    echo $this->jquery_pagination->create_links(); 
    } 
    

    上面的代碼工作...我只是不知道如何讀取過濾器的值「search_database」PHP函數。

    我已經工作過這個例子,但是這就是我似乎可以找到:

    http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline/

    任何人能幫助我們嗎?

    +0

    呃......代碼在預覽窗口中看起來不錯。它只是不是我的一天:(。 – 2010-12-04 18:07:13

    回答

    3

    使用$ .post的'data'部分。

    http://api.jquery.com/jQuery.post/

    $.ajax({ 
        type: 'POST', 
        url: url, 
        data: { $('#form_field').val() }, 
        etc. 
    
    +0

    似乎我發佈了舊版本的代碼。我將以下JSON值傳遞給PHP函數{「serialised_form」:$('#search_form')。serialize()} 我可以使用$ this-> input-> post('serialised_form')從PHP方法訪問此數據。 但是,當我單擊分頁鏈接時,表單值不會發送... – 2010-12-04 18:43:09

    0

    得到它的工作傢伙。只是一些愚蠢的錯誤。 只好連載的形式數據,而不是發送它作爲一個JSON對象

    $("#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'); 
        }); 
    }); 
    

    和事實證明,「additional_param」是工作畢竟。

    相關問題