ajax - jQuery mobile $(document).ready equivalent -
in ajax navigation pages, classic "document ready" form performing initialization javascript doesn't fire.
what's right way execute code in ajax loaded page?
(i mean, not ajax... it's jquery mobile page navigation system brings me page)
ok, did suspect that... lot =) but... still doesn't work, here's code:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>mypage</title> <link rel="stylesheet" href="jquery.mobile-1.0a4.min.css" /> <script type="text/javascript" src="jquery-1.5.min.js"></script> <script type="text/javascript" src="jquery.mobile-1.0a4.min.js"></script> <script type="text/javascript"> $('div').live('pageshow',function(event, ui){ alert('ciao'); }); </script> </head> <body> <div data-role="page"> <div data-role="header" data-position="fixed"> <h1>shopping cart</h1> </div> <div data-role="content"> asd </div> </div> </body> do need specify div id?
i spent time on researching same since jqm docs not detailed @ point. solution below works fine me:
<script type="text/javascript"> $('div:jqmdata(role="page")').live('pagebeforeshow',function(){ // code execute on each page change }); </script> you have implement own checking flow in order prevent multiple initialization since code above run on every page change
Comments
Post a Comment