簡體   English   中英

同一頁面中的AJAX加載會導致div重復出現

[英]AJAX load in same page causes divs to repeat

我正在對同一頁面執行ajax調用,但是它會重新加載現有的div。 我想知道是否有辦法壓制它? 這里有更多細節:

我的項目設置

index.php - 打開記錄控制器

/**app logic**/

view('open',$data); //require '../views/layout.php';

layout.php中

/*all the js scripts and stylesheets loaded here*/

<div id='logo'></div>
<div id='nav'></div>

include($path); //loads the open.view.php file

open.view.php

/*AJAX call to self*/


function getViaAjax(chosenGroup){
    $.post('index.php',{group:chosenGroup},
                function(data)
                {   
                    $("#default").remove();
                    $('#group-tickets').html(data);
                });
}

正如您可能知道的那樣,這會導致#logo#nav div在頁面上重復。 我知道我可以將AJAX帖子發送到另一個文件,我會徹底解決這個問題,但我想知道是否有辦法做到這一點?

試試這個鏈接 文檔說明: The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted.

$('#result').load('ajax/test.html #container');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM