I am using:
$('#mypage').live("pageinit", function(){
$('#mypage').bind('pageshow', function() {
//json gets data here
}...etc
My problem is that the code is not getting a fresh page, just adding the same content every time I go to the page.
so:
Page load … I go to #mypage and I get:
eg:
A. some content here
then if I load the page again I get 2 instances of the same:
A. some content here
A. some content here
and so on.
I need to it updates everytime but no merge the data.
Update:
Pageshow Code here:
$('#mypage').bind('pageshow', function() {
$.getJSON("http://mysite/api/get_data", function(data){
var output = '';
$.each(data.mydata, function(index, value){
output += '<li><a href="#"><img src="'+value.thumbnail_url+'" /><h3>'+value.title+'</h3>'+value.body+'</a></li>';
});
$('#my_listview').append(output).listview('refresh');
}).error(function(args) {
console.log(args);
});
});//end of pageshow
How can I fix this?
The problem is that you always append data to the my_listview element.
Replace the
$('#my_listview').append(output)with$('#my_listview').html(output)and the problem will be fixed.