2015-11-03 95 views
0

一個鏈接所以基本上我有一個鏈接爲div在第1頁顯示從另一個PHP頁面,而頁面重載

<a href="/computing/abc/page2.php" class="topic-list-item"> 

    <h3 class="topic-title">Internet Protocol Basics</h3> 

    <div class="topic-description-text"> 
     Learn how Internet Protocol is used 
    </div> 
</a> 

當我點擊它被重新加載頁面打開頁面2 div

我希望第2頁的新內容在沒有任何重新加載的情況下顯示,同時這也改變了我的網址。

這可能嗎?

+0

您將需要使用AJAX調用和修改當前的URL – EoiFirst

+0

@EoiFirst可以請你給我一個例子 – Neha

+0

沒有重裝 – MaggsWeb

回答

0

HTML:

禁用您<a>標記,因爲你會改爲發送加載了新的一頁的一個Ajax請求

<a href="#" data-url="/computing/abc/page2.php" class="topic-list-item"> 

    <h3 class="topic-title">Internet Protocol Basics</h3> 

    <div class="topic-description-text"> 
     Learn how Internet Protocol is used 
    </div> 
</a> 

JS(jQuery的):

綁定click事件來執行你的ajax調用,然後將您的服務器發回的HTML設置到您想要的位置。

$("a").click(function(){ 
    $.ajax({ 
     url: $(this).data("url"), 
     method: 'get', 
     success: function(data){ 
     $("#targetContainer").html(data); 
     } 
    }) 
    }); 

success函數的參數將是你的服務器發回的/computing/abc/page2.php頁。您可以將其設置在您需要的頁面上(在$("#targetContainer")之內)。

Modify the URL without reloading the page的URL修改不重裝

+0

不能更改網址你能否澄清#ThePlaceWhereYouWantToPutTheNewHTML。另外,我有10個這樣的div,這意味着我將有10個Ajax電話? 我確實嘗試過pushState,但它不適合我的目的。 – Neha

+0

我錯了 - 它不起作用,我想改變完整的html而不僅僅是一個div。 – Neha

相關問題