2013-08-25 176 views
-1

問題看起來很簡單,但不知何故,它不適合我。索引頁上有一個用戶圖像。點擊此圖片,應出現用戶個人資料頁面。
的index.phpCodeigniter:用jQuery打開另一個頁面

$('#user-navbar').click(function() { 
    $.ajax({ 
     url: "<?php echo site_url('gallery/userProfile');?>", 
     type: 'GET' 
    }); 
}); 

畫廊控制器

function userProfile() 
{ 
    $this->load->view('userprofile'); 
} 

當我點擊用戶圖像沒有任何反應。現在我沒有將任何數據傳遞給userprofile頁面。只是想顯示該頁面。

+0

你不會除非將響應文本添加到DOM元素,否則可以使用ajax「顯示頁面」,您應該閱讀關於AJAX如何工作的更多信息 –

+0

@koala_dev感謝您使用我的方法識別問題。你想建議一個解決方案嗎? –

+0

你想要做什麼?你想在哪裏出現頁面? –

回答

0

試試這個:

$('#user-navbar').click(function() { 
     var url = "<?php echo base_url(); ?>gallery/userProfile"; 
     $(location).attr('href',url); 
     }); 
0

試試這個

加載你的看法變成一個變量,並傳遞給視圖,然後將其附加到現有的div

public function userProfile() 
{ 
    $my_view = $this->load->view('userprofile','',true); 
    echo json_encode($my_view); 
} 



$('#user-navbar').click(function() { 

     $.ajax({ 
       url: "<?php echo base_url(); ?>gallery/userProfile", 
       dataType:'json', 
       type: 'POST' 
       success: function(data) { 
        $('#your_div').append(data); 
       } 
      }); 
     }); 
相關問題