且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在jQuery Mobile中的Ajax调用上显示页面加载微调器

更新时间:2023-10-24 12:03:04

一些人问到我最终实现的变通办法,因此我想与大家分享.它并没有什么特别的优雅或复杂之处,但它确实起作用了.自从正式版1.0发布以来,我就没有使用过该框架,因此在更新中可能已经解决了这一问题.本质上,我将$.mobile.showPageLoadingMsg()调用放入了pageshow函数中,但将其包装在if子句中,该子句仅在第一次显示该页面时触发:

A few people have asked about the workaround I ended up implementing, so I figured I'd share it. It's nothing particularly elegant or complicated, but it did seem to work. I haven't used the framework since the official 1.0 was released, so this may have been solved in the update. Essentially, I put the $.mobile.showPageLoadingMsg() call into the pageshow function, but wrapped it in an if clause that only fires the first time the page is shown:

var mainloaded = false;

$('#main').live('pageshow', function(event) {   //Workaround to show page loading on initial page load
    if(!mainloaded) {
    $.mobile.showPageLoadingMsg();
    }
});

$('#main').live('pagecreate', function(event) { 
    $.ajax({
        url: //url
        dataType: //datatype,
        headers: //headers
        success: function(data) {
            //
            //...loading stuff
            //
            $.mobile.hidePageLoadingMsg();
            mainloaded = true;
        }
        //
        //...handle error, etc.
        //
    });
});