简体   繁体   中英

Jquery event like $(window).load for partial view

I have event that fires on window.load

$(window).load(function () {...});

But I have logic on this page which update partial view. After this logic I also want to execute window.load .

How can I do this?

Document ready doens't help

Assuming that you're using jQuery's ajax to load the partial views:

First, you'll want to separate out the code that happens on both full and partial loads:

    function OnLoadTasks() {
    // stuff that happens on every load.
    }
    $(window).load(function () {
        OnLoadTasks();
        // Other stuff that only happens on full load, if any
    });

Then you can easily call that function again later:

$.ajax(...)
.done(function(r) {
    // Do whatever tasks need to be done to load the data
    OnLoadTasks();
});

$.ajax() could also be one of the shortcuts, like $.get() or $.load()

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