我试图在初始应用程序/站点初始化期间以及每次用户返回#index页面时显示JQM 1.2 RC-1,加载消息.我对如何做到这一点的理解如下,但是,它没有像我期望的那样工作.这不显示加载消息.
$('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 )
}
})
})
Run Code Online (Sandbox Code Playgroud)
我在这里找到的解决方法(stackoverflow)用于显示加载时的加载消息.
$('#index').live('pageshow', function(event) { //Workaround to show page loading on initial page …Run Code Online (Sandbox Code Playgroud)