I am trying to show the, JQM 1.2 RC-1, loading message during initial application / site init and every time a user returns to the #index page. My understanding of the way to do this would be as follows, however, it is not working as I expect. This does not show the loading message.
$('body').on('pagebeforeshow', '#index', function(){
$.mobile.loading('show')
$('#index ul li').remove()
var post_data = {
action: 'an_action',
method: 'method'
}
$.ajax({
type: 'POST',
url: ajaxurl,
data: post_data,
cache: false,
dataType: 'text',
cache: false,
success: function(response) {
$('#index ul').append(response)
$('#index ul').listview('refresh')
$.mobile.loading('hide')
},
error: function(jqXHR, textStatus, errorThrown) {
console.log( ' => ' + jqXHR + ' => ' + textStatus + ' => ' + errorThrown )
}
})
})
The workaround I found on here(stackoverflow) works to show the loading message on load.
$('#index').live('pageshow', function(event) { //Workaround to show page loading on initial page load
$.mobile.loading('show')
})
The problem I am experiencing is when I navigate back to the #index and the loading message is sometimes removed and other times it remains.
If the loading message is active and I click a link to leave the current page, the loading message is removed as expected. When I return from the same link to the #index the loading message is sometimes removed without refreshing the page in browser.
Is there another method to achieve the loading message on initial application / site load?
Additional info:
Tested on iDevice running Safari iOS 6 and Chrome, Mac OSX Chrome, Safari, Firefox, Opera with same results.
jQuery Mobile 1.2 RC-1
I am using single page template and injecting server data into lists then transitioning to different page #id's.
I've tried with no success:
$('#index').live('pageinit', function(event) {
$.mobile.loading('show')
})
The $.ajax() is successfully being triggered and completed as I can change server data and it is consistently changed within the application.
This is confusing since the $.mobile.loading('hide') should also be triggered and hide the loading message since the response is successful. This leads me to believe it is not a caching issue.
This is what I did, I added a div to my content with class="my_style" which is initially hidden and when the showpageloading message is displayed, these are the two custom functions to display it and hide it:
function showCustomPageLoadingMsg(){
$('.my_style').css('display','inline');
}
function hideCustomPageLoadingMsg(){
$('.my_style').css('display','none');
}
and this is how I called the functions:$.mobile.showCustomPageLoadingMsg('f','Lookup in Progress', true);
and $.mobile.hideCustomPageLoadingMsg();
Another difference between my code and yours is that I put the ajax call and the called that function inside .live:
function test(){
$.mobile.showCustomPageLoadingMsg('f','Lookup in Progress', true);
$('#index ul li').remove()
var post_data = {
action: 'an_action',
method: 'method'
}
$.ajax({
type: 'POST',
url: ajaxurl,
data: post_data,
cache: false,
dataType: 'text',
cache: false,
success: function(response) {
$.mobile.hideCustomPageLoadingMsg();
$('#index ul').append(response)
$('#index ul').listview('refresh')
},
error: function(jqXHR, textStatus, errorThrown) {
console.log( ' => ' + jqXHR + ' => ' + textStatus + ' => ' + errorThrown )
}
})
}
$('#index').live('pageinit', function(event) {
test();
});
Loop holes in your code:
;
This is a standard delimiterHappy hacking!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With