2012-11-13 39 views
0

這是我的test.php頁面,我想加載在<< id="new-nav" >>外部頁面的內容。加載點擊從外部li

的塞納里奧如下:我想點擊從我的菜單裏這是在<?php include 'Menu/Side-menu.html.php'; ?>並在<< id="new-nav" >>區域

<div id="left"> 
<?php include 'Menu/Side-menu.html.php'; ?> 
</div> 

<div id="main"> 
<p>This is a test</p> 

<b>see the text:</b> 
<ol id="new-nav"></ol> 
</div> 

<script> 
$(document).ready(function(){ 

    $("#test li").click(function (e) { 

    // Stop the link from changing the page 
    e.preventDefault(); 

    // Your jQuery code. 
    $("#new-nav").load(('Menu/Side-menu.html.php').attr("href")); 
    }); 

}); 
</script> 
+4

你期望得到這個代碼:('Menu/Side-menu.html.php')。attr(「href」)??? –

+1

我不知道Menu/Side-menu.html.php裏面有什麼,但爲什麼你的php包含它,然後再通過AJAX在同一頁面中加載? – Tivie

+0

可能是因爲我不知道該怎麼辦,我有我的菜單包含它,所以我可以使用我的所有頁面 –

回答

0

我建議你使用這個加載在test.php的內容解決方案,而不是:

$("#test li").click(function (e) { 

    // Stop the link from changing the page 
    e.preventDefault(); 

    // Your jQuery code. 
    $.post('Menu/Side-menu.html.php',function(response) { // (added quotes) 
     $("#new-nav").html(response); 
    }); 
}); 
+0

我有意想不到的令牌} $(「#test li」)。click(function(e ){ //更改頁面 e.preventDefault停止鏈接(); //你的jQuery代碼 $。員額(菜單/側面menu.html.php,函數(響應){$ ( 「#新導航」)HTML(響應);} }); –

+0

亞歷山德羅沒有工作的人, –

+0

周圍添加URL報價 - '菜單/側面menu.html.php' 和 「);」之後「}」 – oyatek