asp.net-mvc-4jquery-mobilejquery-eventsrazor-2

jQuery Mobile, MVC 4 Razor, Page (or view) Change Event


I'm sure that some folks have come across this scenario before. I need JavaScript to fire every time the user navigates to a new View. Please see the shared view (stripped down) below:

The 2 events will fire when you first open the website, but not on subsequent navigation:

<!DOCTYPE html> 
<html lang="en">
<head>
</head>
<body class="ui-mobile-viewport">
<div data-role="page" id="div_page" data-theme="ss">
<div data-role="content" role="main" id="div_body" class="ui-content">
@RenderBody()
</div>
</div>
</body>
</html> 

$(document).on("pageinit", "#div_page", function () {});
$(document).ready(function () {});

Which event captures the page change event? The "change" event? The "DOMContentLoaded" event? Please advise.


Solution

  • By default, each request will be ajax request while using jquery mobile. Though you can try with $(document).on('pagecreate', function(){...});