$('#home').live('pageshow', function(event) {
$.mobile.showPageLoadingMsg();
var task = getUrlVars()["que"];
var page = getUrlVars()["page"];
var query = '';
if(page == undefined){
page = 0;
}
var nextPage = page+1;
if(task == undefined){
task = 'home';
}
switch(task){
case 'home':
query = 'task=home&page='+page;
break;
}
$.get('http://myappserver.com/api.php?'+query,function(data,response){
alert(response);
alert(data);
var json = eval(data);
var list = '';
for (var i=0;i<json.length;i++){
var item = json[i];
var img = 'http://myappserver.com'+item.img;
list += '<li><a href="page.html?id=' + item.id + '">' +
'<img src="' + img + '" class="recipeAvatarList"/>' +
'<h4>' + item.value + '</h4>' +
'<p>' + item.familia + '</p>' +
'<span class="ui-li-count">' + item.votos + '</span></a>';
+'</li>';
}
list += '<li><a href="index.html?que='+task+'&page='+nextPage+'">Cargar más..</a></li>';
$('#mainlist').html(list).listview('refresh');
$.mobile.hidePageLoadingMsg();
});
});
WHERE
function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
This seems to work great lo load the results in the first page, but if you notice, i append a link to load the next page:
list += '<li><a href="index.html?que='+task+'&page='+nextPage+'">Cargar más..</a>
The thing is that when that link is clicked it loads the next URL properly, and the data and response alert are with the expected content but the list is not filled... User must manually refresh that view to do so..
Is this because i shouldnt use .live('pageshow')
?
-EDIT-
Page markup is like this
<div id="home" data-role="page" >
<header role="banner" class="clearfix" >
<h1>Title</h1>
</header>
<div data-role="content">
<div class="">
<input type="search" id="buscar_receta" placeholder="busca recetas" />
<a href="search.html" class="advancedSearchLink">+ Busqueda avanzada</a>
</div>
</div>
<div data-role="content">
<ul id="mainlist" data-role="listview" >
</ul>
</div>
</div>