简体   繁体   中英

jQuery multiple ajax load same dynamic page

I have a page which has dynamic content and its content changing with parameters.

I'm trying to comparison different department courses. First I select computer science and load its courses my first div at left. (#list1)

After load first content, I change department to industrial engineering and I click second button to load course list to second div (#list2)

But when i load second div first div content changes like second (industrial engineering). Bu if i load second div first its working! (But its not acceptable for client)

My code like this,

<div class="row">
<div class="col-md-12">
    <div class="col-md-6">
        <div id="list1"></div>
    </div>
    <div class="col-md-6">
        <div id="list2"></div>
    </div>
</div>
</div>

And button click events

$(document).on("click", ".btn-listele", function () {

        var direction = $(this).attr("data-taraf");
        var send2 = $.post("/Intibak/DersIntibak/CleanIntibakDers");
        send2.done(function () {
        if (direction == "sol") {
            $("#list1").load("/Genel/BolumPlan/IntibakDersPlan?guncelMi=true&groupable=true");
        }
        if (direction == "sag") {
            $("#list2").load("/Genel/BolumPlan/IntibakDersPlan?guncelMi=true&groupable=true");
        }
        });
    });

note: if I change div order like above then the problem reverse.

<div class="row">
<div class="col-md-12">
    <div class="col-md-6">
        <div id="list2"></div>
    </div>
    <div class="col-md-6">
        <div id="list1"></div>
    </div>
</div>
</div>

My button code

<span class="btn btn-info pull-right btn-listele" id="btn-listele-sol" data-taraf="sol">Ders Planlarını Listele</span>

<span class="btn btn-info pull-right btn-listele" id="btn-listele-sag" data-taraf="sag">Ders Planlarını Listele</span>

It appears that what you're loading into '#list1' and '#list2' comes from the exact same data source.

Is the result of /Genel/BolumPlan/IntibakDersPlan?guncelMi=true&groupable=true" ever different? If not, you will end up with the same data in each div.

Script Execution

When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed. An example of both cases can be seen below:

Here, any JavaScript loaded into #a as a part of the document will successfully execute.

$( "#a" ).load( "article.html" );

However, in the following case, script blocks in the document being loaded into #b are stripped out and not executed:

$( "#b" ).load( "article.html #target" );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM