Here is my problem. There are several hardcoded pseudo pages in my index. Some are filled with content, some are empty, which will be filled during user interaction using only ajax. This ajax content contains html lists. When they load, they donβt have an attractive jquery mobile view, so I have to call the .listview () method, so the jqm structure will parse it on my ajax callback. This is where I often get this JS error:
Uncaught TypeError: Cannot read property 'jQuery162027575719612650573' from undefined
The number is never the same ...
I wonder if I'm using the right way to parse a list when a page loads ajax content. the error seems to be triggered when there is a slight delay for loading, and the full event fires too early, and my list is not in the DOM yet at this point, just a hunch. What is the recommended way to initialize a list after ajax call?
This is very sad, because when a js error occurs, it seems to freeze the further execution of js ...
so here is my empty pseudo page:
<div data-role="page" id="playlist" data-add-back-btn="true"> <div data-role="header"> <h1><g:message code="pd.playlist" /></h1> </div> <div data-role="content"></div> </div>
right below it there is a script tag with an ajax call binding on the pages to activate listview
<script type="text/javascript"> $('#playlist').bind('pageshow', function () { $.ajax({ url: "updatePlaylistTemplate.gsp", error:function(x,e){handleAjaxError(x,e);}, beforeSend:function(){$.mobile.showPageLoadingMsg();}, complete:function(){ $.mobile.hidePageLoadingMsg(); $('[data-role="listview"]').listview(); </script>
UpdatePlaylistTemplate returns this (extract):
<ul data-role="listview" data-split-theme="d"> <li data-icon="delete"> <a href="javascript:void(0);" onclick="loadGet('urlToRemoveProdiver',$('#playlist'),doOnCallBack);">Provider: Bell</a> </li> <li data-icon="delete"> <a href="javascript:void(0);" onclick="loadGet('urlToRemoveChannel',$('#playlist'),doOnCallBack);">Rock - Classic Rock</a> </li> <li data-icon="refresh" data-theme="e"><a href="javascript:void(0);" onclick="loadGet('urlToReloadPlaylist',$('#playlist'),doOnCallBack)">Refresh list</a></li> <li data-role="list-divider">Next song</li> <li> <a href="urlToViewSongInfo"> <img src="images/song.gif" /> <h3>Albert Flasher</h3> <p>The Guess Who</p> <p class="ui-li-aside">Next</p> </a> </li> <li data-role="list-divider">Now playing</li> <li> <a href="urlToviewSongInfo"> <img src="images/song.gif" /> <h3>Crime of the Century</h3> <p>Supertramp</p> <p class="ui-li-aside">14h49</p> </a> </li> <li data-role="list-divider">Previous songs</li> <li> <a href="urlToViewSongInfo"> <img src="images/song.gif"" /> <h3>Desperado</h3> <p>Alice Cooper</p> <p class="ui-li-aside">14h45</p> </a> </li> [...] </ul>