简体   繁体   中英

Jquery window.unload event called after controller action when refreshing the page

I have a page when a content is edited. when a user comes to this edit page we lock the content by setting IsLocked = true and when a user navigates to different page we unlock it by using Jquery window.unload event.

This works fine in all cases. But when we refresh the page the controller gets called first and after that window.Unload event is called.

So in this way the content gets locked first and then gets unlocked.

Any suggestions to identify the page refresh and restrict unlocking of the content? or how to call the jquery.unload event before controller action?

$(window).on('unload',function () {

    $.ajax({
        url: 'unlockcontent' + contentId
        async: false,
        success: function () {
        }
    });
});

尝试使用beforeunload事件而不是unload事件。

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