Search code examples
jquery-mobileloadingtransitionpageload

jquery mobile $.mobile.showpageloadingmsg() is not working


I wish to show loading message during page transition in jQM and backbone. But the showPageLoadingMeassage isnt working. Following is my code: collection.js

findById : function(artistId, page, limit, sort) {
    $.mobile.showPageLoadingMsg('a', 'Loading......', false);
    var self = this;
    if (limit == undefined) {
        limit = 10;
    }
    $.mobile.showPageLoadingMsg('a', 'Loading......', false);
    console.log("hello");
    $.ajax({
        type: "GET",
        url: siteURL + 'artists/artist_detail/artist_id'  + artistId  + '.json',
    }).done(function(msg) {
        var response = JSON.parse(msg);

        if (response.status == true) {
            var dataArray = response.data;
            console.log(dataArray);
            self.reset(dataArray);

            if (self.length > 0) {
                $.mobile.hidePageLoadingMsg();
            }
            //return  dataArray;
        } $.mobile.showPageLoadingMsg($.mobile.pageLoadErrorMessageTheme, 'Sorry! No records found', true);
            setTimeout(function() {
                $.mobile.hidePageLoadingMsg();
            }, 1500);
        }
    });
}

where am i getting wrong?

edited: it works when for search page:

... findByTitle : function(keyword, genre, language, page, limit, sort, collection, fan, featured) {
            //~ console.log(page);
            var self = this;
            if (limit == undefined) {
                limit = 10;
            }
            $.mobile.showPageLoadingMsg('a', 'Searching......', false);
            $.ajax({....

Solution

  • found the answer on stackoverflow itself- jQuery Mobile - Problems getting showPageLoadingMsg to work with pagebeforeshow or pagebeforeceate. It says that sometimes jQM doesn't adds the ui-loading class to the body so we have to do it manually.

    $('body').addClass('ui-loading');
        $.mobile.showPageLoadingMsg('a', 'Searching......', false);
    

    and while hiding the loading msg:

    setTimeout(function() {
        $('body').removeClass('ui-loading');   //remove class
        $.mobile.hidePageLoadingMsg();
    }, 1000);