How to refresh a DIV in jquery (mobile)?












7















UPDATE: Sorry, I accidentally copied the data-dom-cache="true" line into my content-div. Seems very logical that the app is loading from the dom instead the new content! I've changed it to false and now it works perfectly.



Thanks.



I have a list which is dynamically generated. If someone is clicking on an entry in the list, the user is redirected to a new page where the data is loaded (dynamically). The data which is loaded depends on the list entry which the user has clicked.



When the app is loaded the first time, all things work well. But when the user is clicking on another list entry, the same data are represented as on the first run.



I've played around with the .empty() function from jQuery (to clear the div and append the new data) but it doesn't work.



EDIT:



My headlines.html file looks like this:



<div id="content>
<div id="headlineslist">
<ul data-role="listview" data-theme="c" id="headlineslist">
</ul>
</div>
</div>
<script>
$(document).ready(function() {
HeadlinesLoad();
});
</script>


Here's the Javascript file:



function HeadlinesLoad() {
$.ajax({
type: "POST",
url: "headlines_getter.php",
dataType: 'json',
cache: false,
success: function(data1) {
$.each(data1, function(i, currentObj) {
$('ul#headlineslist').append('<li data-role="list-divider"
class=​"ui-li ui-li-divider ui-bar-b">​' + currentObj.main + '</li>​').listview('refresh');
$.each(currentObj.sub, function (j, currentSub) {
$('ul#headlineslist').append('<li>
<a href="headlinesclicked_temp.html" onclick="headlineID(' + currentSub.sid + ')">' + currentSub.name + '</a></li>').listview('refresh');
});
});
}
});
}

function headlineID(hID) {
window.localStorage.setItem("headlineID", hID);
}

function onHeadlinesLoad() {
var hID = window.localStorage.getItem("headlineID");
window.localStorage.removeItem("headlineID");
window.localStorage.clear();
$.ajax({
url: "headlinesclicked_getter.php?hID=" + hID,
success: function(html) {
if(html){
$("#headlineshome").empty();
$("#headlineshome").html(html);
}
}
});
}


And here is the snippet which lays in the HTML file where the data should be displayed (and refreshed on every new click the user does):



<div data-role="content" id="headlineshome"></div>
<script>
$(document).ready(function() {
onHeadlinesLoad();
});
</script>


I don't know why it doesn't work, so I ask you for help.



Thanks in advance.



Best regards, John.










share|improve this question

























  • Sorry for asking this, but have you made sure this is not a caching issue? Maybe the mobile browser thinks he's smarter than the "cache: false"-Param?

    – Lukx
    May 21 '12 at 21:34











  • stackoverflow.com/questions/5562461/…

    – lukas.pukenis
    May 21 '12 at 21:35











  • With jQuery mobile you need to trigger "create" event in order for refreshing to happen. It costs performance to refresh everything on a mobile device :)

    – lukas.pukenis
    May 21 '12 at 21:35











  • And what's up with the double-declaration of onHeadlinesLoad? You might want to tidy that bit up first. Then, once that is done, you tell us where hID, which you all of a sudden use in your second onHeadlinesLoad, comes from.

    – Lukx
    May 21 '12 at 21:42











  • @Lukx: sorry for the double-declaration, was an copy failure. I've corrected that in my question. The hID is retrieved from the onclick function in the first function (function HeadlinesLoad()), which is retrieved from my php-file.

    – John Brunner
    May 21 '12 at 21:49
















7















UPDATE: Sorry, I accidentally copied the data-dom-cache="true" line into my content-div. Seems very logical that the app is loading from the dom instead the new content! I've changed it to false and now it works perfectly.



Thanks.



I have a list which is dynamically generated. If someone is clicking on an entry in the list, the user is redirected to a new page where the data is loaded (dynamically). The data which is loaded depends on the list entry which the user has clicked.



When the app is loaded the first time, all things work well. But when the user is clicking on another list entry, the same data are represented as on the first run.



I've played around with the .empty() function from jQuery (to clear the div and append the new data) but it doesn't work.



EDIT:



My headlines.html file looks like this:



<div id="content>
<div id="headlineslist">
<ul data-role="listview" data-theme="c" id="headlineslist">
</ul>
</div>
</div>
<script>
$(document).ready(function() {
HeadlinesLoad();
});
</script>


Here's the Javascript file:



function HeadlinesLoad() {
$.ajax({
type: "POST",
url: "headlines_getter.php",
dataType: 'json',
cache: false,
success: function(data1) {
$.each(data1, function(i, currentObj) {
$('ul#headlineslist').append('<li data-role="list-divider"
class=​"ui-li ui-li-divider ui-bar-b">​' + currentObj.main + '</li>​').listview('refresh');
$.each(currentObj.sub, function (j, currentSub) {
$('ul#headlineslist').append('<li>
<a href="headlinesclicked_temp.html" onclick="headlineID(' + currentSub.sid + ')">' + currentSub.name + '</a></li>').listview('refresh');
});
});
}
});
}

function headlineID(hID) {
window.localStorage.setItem("headlineID", hID);
}

function onHeadlinesLoad() {
var hID = window.localStorage.getItem("headlineID");
window.localStorage.removeItem("headlineID");
window.localStorage.clear();
$.ajax({
url: "headlinesclicked_getter.php?hID=" + hID,
success: function(html) {
if(html){
$("#headlineshome").empty();
$("#headlineshome").html(html);
}
}
});
}


And here is the snippet which lays in the HTML file where the data should be displayed (and refreshed on every new click the user does):



<div data-role="content" id="headlineshome"></div>
<script>
$(document).ready(function() {
onHeadlinesLoad();
});
</script>


I don't know why it doesn't work, so I ask you for help.



Thanks in advance.



Best regards, John.










share|improve this question

























  • Sorry for asking this, but have you made sure this is not a caching issue? Maybe the mobile browser thinks he's smarter than the "cache: false"-Param?

    – Lukx
    May 21 '12 at 21:34











  • stackoverflow.com/questions/5562461/…

    – lukas.pukenis
    May 21 '12 at 21:35











  • With jQuery mobile you need to trigger "create" event in order for refreshing to happen. It costs performance to refresh everything on a mobile device :)

    – lukas.pukenis
    May 21 '12 at 21:35











  • And what's up with the double-declaration of onHeadlinesLoad? You might want to tidy that bit up first. Then, once that is done, you tell us where hID, which you all of a sudden use in your second onHeadlinesLoad, comes from.

    – Lukx
    May 21 '12 at 21:42











  • @Lukx: sorry for the double-declaration, was an copy failure. I've corrected that in my question. The hID is retrieved from the onclick function in the first function (function HeadlinesLoad()), which is retrieved from my php-file.

    – John Brunner
    May 21 '12 at 21:49














7












7








7


1






UPDATE: Sorry, I accidentally copied the data-dom-cache="true" line into my content-div. Seems very logical that the app is loading from the dom instead the new content! I've changed it to false and now it works perfectly.



Thanks.



I have a list which is dynamically generated. If someone is clicking on an entry in the list, the user is redirected to a new page where the data is loaded (dynamically). The data which is loaded depends on the list entry which the user has clicked.



When the app is loaded the first time, all things work well. But when the user is clicking on another list entry, the same data are represented as on the first run.



I've played around with the .empty() function from jQuery (to clear the div and append the new data) but it doesn't work.



EDIT:



My headlines.html file looks like this:



<div id="content>
<div id="headlineslist">
<ul data-role="listview" data-theme="c" id="headlineslist">
</ul>
</div>
</div>
<script>
$(document).ready(function() {
HeadlinesLoad();
});
</script>


Here's the Javascript file:



function HeadlinesLoad() {
$.ajax({
type: "POST",
url: "headlines_getter.php",
dataType: 'json',
cache: false,
success: function(data1) {
$.each(data1, function(i, currentObj) {
$('ul#headlineslist').append('<li data-role="list-divider"
class=​"ui-li ui-li-divider ui-bar-b">​' + currentObj.main + '</li>​').listview('refresh');
$.each(currentObj.sub, function (j, currentSub) {
$('ul#headlineslist').append('<li>
<a href="headlinesclicked_temp.html" onclick="headlineID(' + currentSub.sid + ')">' + currentSub.name + '</a></li>').listview('refresh');
});
});
}
});
}

function headlineID(hID) {
window.localStorage.setItem("headlineID", hID);
}

function onHeadlinesLoad() {
var hID = window.localStorage.getItem("headlineID");
window.localStorage.removeItem("headlineID");
window.localStorage.clear();
$.ajax({
url: "headlinesclicked_getter.php?hID=" + hID,
success: function(html) {
if(html){
$("#headlineshome").empty();
$("#headlineshome").html(html);
}
}
});
}


And here is the snippet which lays in the HTML file where the data should be displayed (and refreshed on every new click the user does):



<div data-role="content" id="headlineshome"></div>
<script>
$(document).ready(function() {
onHeadlinesLoad();
});
</script>


I don't know why it doesn't work, so I ask you for help.



Thanks in advance.



Best regards, John.










share|improve this question
















UPDATE: Sorry, I accidentally copied the data-dom-cache="true" line into my content-div. Seems very logical that the app is loading from the dom instead the new content! I've changed it to false and now it works perfectly.



Thanks.



I have a list which is dynamically generated. If someone is clicking on an entry in the list, the user is redirected to a new page where the data is loaded (dynamically). The data which is loaded depends on the list entry which the user has clicked.



When the app is loaded the first time, all things work well. But when the user is clicking on another list entry, the same data are represented as on the first run.



I've played around with the .empty() function from jQuery (to clear the div and append the new data) but it doesn't work.



EDIT:



My headlines.html file looks like this:



<div id="content>
<div id="headlineslist">
<ul data-role="listview" data-theme="c" id="headlineslist">
</ul>
</div>
</div>
<script>
$(document).ready(function() {
HeadlinesLoad();
});
</script>


Here's the Javascript file:



function HeadlinesLoad() {
$.ajax({
type: "POST",
url: "headlines_getter.php",
dataType: 'json',
cache: false,
success: function(data1) {
$.each(data1, function(i, currentObj) {
$('ul#headlineslist').append('<li data-role="list-divider"
class=​"ui-li ui-li-divider ui-bar-b">​' + currentObj.main + '</li>​').listview('refresh');
$.each(currentObj.sub, function (j, currentSub) {
$('ul#headlineslist').append('<li>
<a href="headlinesclicked_temp.html" onclick="headlineID(' + currentSub.sid + ')">' + currentSub.name + '</a></li>').listview('refresh');
});
});
}
});
}

function headlineID(hID) {
window.localStorage.setItem("headlineID", hID);
}

function onHeadlinesLoad() {
var hID = window.localStorage.getItem("headlineID");
window.localStorage.removeItem("headlineID");
window.localStorage.clear();
$.ajax({
url: "headlinesclicked_getter.php?hID=" + hID,
success: function(html) {
if(html){
$("#headlineshome").empty();
$("#headlineshome").html(html);
}
}
});
}


And here is the snippet which lays in the HTML file where the data should be displayed (and refreshed on every new click the user does):



<div data-role="content" id="headlineshome"></div>
<script>
$(document).ready(function() {
onHeadlinesLoad();
});
</script>


I don't know why it doesn't work, so I ask you for help.



Thanks in advance.



Best regards, John.







javascript jquery mobile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 19 '17 at 6:38









serializer

568




568










asked May 21 '12 at 21:30









John BrunnerJohn Brunner

1,48573467




1,48573467













  • Sorry for asking this, but have you made sure this is not a caching issue? Maybe the mobile browser thinks he's smarter than the "cache: false"-Param?

    – Lukx
    May 21 '12 at 21:34











  • stackoverflow.com/questions/5562461/…

    – lukas.pukenis
    May 21 '12 at 21:35











  • With jQuery mobile you need to trigger "create" event in order for refreshing to happen. It costs performance to refresh everything on a mobile device :)

    – lukas.pukenis
    May 21 '12 at 21:35











  • And what's up with the double-declaration of onHeadlinesLoad? You might want to tidy that bit up first. Then, once that is done, you tell us where hID, which you all of a sudden use in your second onHeadlinesLoad, comes from.

    – Lukx
    May 21 '12 at 21:42











  • @Lukx: sorry for the double-declaration, was an copy failure. I've corrected that in my question. The hID is retrieved from the onclick function in the first function (function HeadlinesLoad()), which is retrieved from my php-file.

    – John Brunner
    May 21 '12 at 21:49



















  • Sorry for asking this, but have you made sure this is not a caching issue? Maybe the mobile browser thinks he's smarter than the "cache: false"-Param?

    – Lukx
    May 21 '12 at 21:34











  • stackoverflow.com/questions/5562461/…

    – lukas.pukenis
    May 21 '12 at 21:35











  • With jQuery mobile you need to trigger "create" event in order for refreshing to happen. It costs performance to refresh everything on a mobile device :)

    – lukas.pukenis
    May 21 '12 at 21:35











  • And what's up with the double-declaration of onHeadlinesLoad? You might want to tidy that bit up first. Then, once that is done, you tell us where hID, which you all of a sudden use in your second onHeadlinesLoad, comes from.

    – Lukx
    May 21 '12 at 21:42











  • @Lukx: sorry for the double-declaration, was an copy failure. I've corrected that in my question. The hID is retrieved from the onclick function in the first function (function HeadlinesLoad()), which is retrieved from my php-file.

    – John Brunner
    May 21 '12 at 21:49

















Sorry for asking this, but have you made sure this is not a caching issue? Maybe the mobile browser thinks he's smarter than the "cache: false"-Param?

– Lukx
May 21 '12 at 21:34





Sorry for asking this, but have you made sure this is not a caching issue? Maybe the mobile browser thinks he's smarter than the "cache: false"-Param?

– Lukx
May 21 '12 at 21:34













stackoverflow.com/questions/5562461/…

– lukas.pukenis
May 21 '12 at 21:35





stackoverflow.com/questions/5562461/…

– lukas.pukenis
May 21 '12 at 21:35













With jQuery mobile you need to trigger "create" event in order for refreshing to happen. It costs performance to refresh everything on a mobile device :)

– lukas.pukenis
May 21 '12 at 21:35





With jQuery mobile you need to trigger "create" event in order for refreshing to happen. It costs performance to refresh everything on a mobile device :)

– lukas.pukenis
May 21 '12 at 21:35













And what's up with the double-declaration of onHeadlinesLoad? You might want to tidy that bit up first. Then, once that is done, you tell us where hID, which you all of a sudden use in your second onHeadlinesLoad, comes from.

– Lukx
May 21 '12 at 21:42





And what's up with the double-declaration of onHeadlinesLoad? You might want to tidy that bit up first. Then, once that is done, you tell us where hID, which you all of a sudden use in your second onHeadlinesLoad, comes from.

– Lukx
May 21 '12 at 21:42













@Lukx: sorry for the double-declaration, was an copy failure. I've corrected that in my question. The hID is retrieved from the onclick function in the first function (function HeadlinesLoad()), which is retrieved from my php-file.

– John Brunner
May 21 '12 at 21:49





@Lukx: sorry for the double-declaration, was an copy failure. I've corrected that in my question. The hID is retrieved from the onclick function in the first function (function HeadlinesLoad()), which is retrieved from my php-file.

– John Brunner
May 21 '12 at 21:49












1 Answer
1






active

oldest

votes


















0














Once you update your list using jQuery mobile, consider trigger "create" event, however that's out dated, so use



.page() 


on your list like this:



$('ul#headlineslist').page();





share|improve this answer
























  • thanks. but i don't want to append on the list, i want to refresh the #headlineshome with the new content (which should be generated when the user clicks another list entry).

    – John Brunner
    May 21 '12 at 21:54











  • now i've tried it with "$("#categorieshome").html(html).page();" ... but this line produces nothing (now no data is displayed).

    – John Brunner
    May 21 '12 at 21:58











  • What if you try $('#categorieshome').html(html).trigger('create') ?

    – lukas.pukenis
    May 22 '12 at 6:26











  • it runs, but theres also no refresh when the user clicks on another list entry.

    – John Brunner
    May 22 '12 at 7:35











  • thanks for the help, i've found the "mistake"!

    – John Brunner
    May 22 '12 at 10:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10692916%2fhow-to-refresh-a-div-in-jquery-mobile%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Once you update your list using jQuery mobile, consider trigger "create" event, however that's out dated, so use



.page() 


on your list like this:



$('ul#headlineslist').page();





share|improve this answer
























  • thanks. but i don't want to append on the list, i want to refresh the #headlineshome with the new content (which should be generated when the user clicks another list entry).

    – John Brunner
    May 21 '12 at 21:54











  • now i've tried it with "$("#categorieshome").html(html).page();" ... but this line produces nothing (now no data is displayed).

    – John Brunner
    May 21 '12 at 21:58











  • What if you try $('#categorieshome').html(html).trigger('create') ?

    – lukas.pukenis
    May 22 '12 at 6:26











  • it runs, but theres also no refresh when the user clicks on another list entry.

    – John Brunner
    May 22 '12 at 7:35











  • thanks for the help, i've found the "mistake"!

    – John Brunner
    May 22 '12 at 10:31
















0














Once you update your list using jQuery mobile, consider trigger "create" event, however that's out dated, so use



.page() 


on your list like this:



$('ul#headlineslist').page();





share|improve this answer
























  • thanks. but i don't want to append on the list, i want to refresh the #headlineshome with the new content (which should be generated when the user clicks another list entry).

    – John Brunner
    May 21 '12 at 21:54











  • now i've tried it with "$("#categorieshome").html(html).page();" ... but this line produces nothing (now no data is displayed).

    – John Brunner
    May 21 '12 at 21:58











  • What if you try $('#categorieshome').html(html).trigger('create') ?

    – lukas.pukenis
    May 22 '12 at 6:26











  • it runs, but theres also no refresh when the user clicks on another list entry.

    – John Brunner
    May 22 '12 at 7:35











  • thanks for the help, i've found the "mistake"!

    – John Brunner
    May 22 '12 at 10:31














0












0








0







Once you update your list using jQuery mobile, consider trigger "create" event, however that's out dated, so use



.page() 


on your list like this:



$('ul#headlineslist').page();





share|improve this answer













Once you update your list using jQuery mobile, consider trigger "create" event, however that's out dated, so use



.page() 


on your list like this:



$('ul#headlineslist').page();






share|improve this answer












share|improve this answer



share|improve this answer










answered May 21 '12 at 21:39









lukas.pukenislukas.pukenis

7,734103371




7,734103371













  • thanks. but i don't want to append on the list, i want to refresh the #headlineshome with the new content (which should be generated when the user clicks another list entry).

    – John Brunner
    May 21 '12 at 21:54











  • now i've tried it with "$("#categorieshome").html(html).page();" ... but this line produces nothing (now no data is displayed).

    – John Brunner
    May 21 '12 at 21:58











  • What if you try $('#categorieshome').html(html).trigger('create') ?

    – lukas.pukenis
    May 22 '12 at 6:26











  • it runs, but theres also no refresh when the user clicks on another list entry.

    – John Brunner
    May 22 '12 at 7:35











  • thanks for the help, i've found the "mistake"!

    – John Brunner
    May 22 '12 at 10:31



















  • thanks. but i don't want to append on the list, i want to refresh the #headlineshome with the new content (which should be generated when the user clicks another list entry).

    – John Brunner
    May 21 '12 at 21:54











  • now i've tried it with "$("#categorieshome").html(html).page();" ... but this line produces nothing (now no data is displayed).

    – John Brunner
    May 21 '12 at 21:58











  • What if you try $('#categorieshome').html(html).trigger('create') ?

    – lukas.pukenis
    May 22 '12 at 6:26











  • it runs, but theres also no refresh when the user clicks on another list entry.

    – John Brunner
    May 22 '12 at 7:35











  • thanks for the help, i've found the "mistake"!

    – John Brunner
    May 22 '12 at 10:31

















thanks. but i don't want to append on the list, i want to refresh the #headlineshome with the new content (which should be generated when the user clicks another list entry).

– John Brunner
May 21 '12 at 21:54





thanks. but i don't want to append on the list, i want to refresh the #headlineshome with the new content (which should be generated when the user clicks another list entry).

– John Brunner
May 21 '12 at 21:54













now i've tried it with "$("#categorieshome").html(html).page();" ... but this line produces nothing (now no data is displayed).

– John Brunner
May 21 '12 at 21:58





now i've tried it with "$("#categorieshome").html(html).page();" ... but this line produces nothing (now no data is displayed).

– John Brunner
May 21 '12 at 21:58













What if you try $('#categorieshome').html(html).trigger('create') ?

– lukas.pukenis
May 22 '12 at 6:26





What if you try $('#categorieshome').html(html).trigger('create') ?

– lukas.pukenis
May 22 '12 at 6:26













it runs, but theres also no refresh when the user clicks on another list entry.

– John Brunner
May 22 '12 at 7:35





it runs, but theres also no refresh when the user clicks on another list entry.

– John Brunner
May 22 '12 at 7:35













thanks for the help, i've found the "mistake"!

– John Brunner
May 22 '12 at 10:31





thanks for the help, i've found the "mistake"!

– John Brunner
May 22 '12 at 10:31




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10692916%2fhow-to-refresh-a-div-in-jquery-mobile%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft