Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8810533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:08:31+00:00 2026-06-14T03:08:31+00:00

I’m writing a phonegap/jquery mobile app and have an issue I cant seem to

  • 0

I’m writing a phonegap/jquery mobile app and have an issue I cant seem to solve.

When the app loads (device ready and jqm_mobile_init) fire and the app creates/opens a database and checks if a user is signed in (just a flag in the db). If so the app calls $.mobile.changePage(“#home”, {transition:”none”}); to redirect them to the “home” page.

Then on the “home” page pageshow event I grab a load of info from the db and append it to a listview within the home page.

However, the first time this runs (with the $.mobile.changePage event) the pageshow event isn’t trigged (so none of my data gets appended to the listview). If I navigate around the app and then visit the page the data shows fine. This only happens when using $.mobile.changePage to change to the home page.

How can I make pageshow() fire on $.mobile.changePage? or is there another way to do it?

Heres my code:

/************************************************
Try to create/open the DB, if not catch the error
***********************************************/
try {
    if (!window.openDatabase) {
        alert('not supported');
    } else {
        var shortName = 'test';
        var version = '1.0';
        var displayName = 'test Database';
        var maxSize = 200000; // in bytes
        // database instance in db.
        var db = openDatabase(shortName, version, displayName, maxSize);

        // Create tables
        createTables(db);

        // Check if there is a signedin user
        isUserSignedInQuery(db);

    }
} catch(e) {
    // Error handling code goes here.
    if (e == 2) {
        // Version number mismatch.
        alert("Invalid database version.");
    } else {
        alert("Unknown error "+e+".");
    }
    return;
}

// Universal null/blank data handler
function nullDataHandler(transaction, results) { }

// Universal error callback
function errorHandler(error) {
    //alert("Error processing SQL: " +error.message+ " Error Code: " +error.code);
}

// Create tables if dont already exist
function createTables(db) {
    db.transaction(
        function (transaction) {

            // create tables
    }
    );
}

/**********************************************************************************************
Check if there is a signed in user, if so redirect to listings page, if not display login page
**********************************************************************************************/

function isUserSignedInQuery(db) {
    db.transaction(
        function (transaction) {
            transaction.executeSql("SELECT * FROM USERS WHERE signedIn=1;",
            [], // array of values for the ? placeholders
            isUserSignedInDataHandler, errorHandler);
        }
    );
}

function isUserSignedInDataHandler(transaction, results) {
    // Handle the results
    if (results.rows.length > 0) {
        //console.log("someones logged in!");

        // Assign signed in user to global var
        console.log("logged in user = " + results.rows.item(0).id);
        window.currentSignedInUserId = results.rows.item(0).id;

        $.mobile.changePage( "#home", { transition: "none"} );
    } else {
        $.mobile.changePage( "#login", { transition: "none"} );
    }
}


/**********************************************************************************************
Sign in page:
**********************************************************************************************/

function doesSigningInUserAlreadyExistQuery(db) {
    db.transaction(
        function (transaction) {
            transaction.executeSql("SELECT * FROM USERS WHERE username='"+usernameValue+"' ORDER BY id LIMIT 0,1;",
            [], // array of values for the ? placeholders
            doesSigningInUserAlreadyExistDataHandler, errorHandler);
        }
    );
}

function doesSigningInUserAlreadyExistDataHandler(transaction, results) {

    // User exists, sign them in.
    if (results.rows.length > 0) {

        //console.log("user exists");

        // Find number of rows
        var len = results.rows.length;
        //console.log(len);

        for (var i=0; i<len; i++){
            //console.log(results.rows.item(i));

            db.transaction(
                function (transaction) {
                    transaction.executeSql('UPDATE USERS SET signedIn = 1 WHERE username="'+usernameValue+'"');
                }               
            );

            // Assign signed in user to global var
            window.currentSignedInUserId = results.rows.item(0).id;

            // Redirect to home/listings page
            $.mobile.changePage( "#home", { transition: "slidefade"} );
        }

    // User is new, create them and sign them in
    } else {

        db.transaction(
            function (transaction) {
                transaction.executeSql('INSERT INTO USERS (username, password, userId, defaultHandler, autoSync, updateCaseTypes'
                +', updateHistorical, updateFavorite, signedIn) '
                +'VALUES ("'+usernameValue+'", "eclipse", "userid321", "Another User", 1, 1, 1, 1, 1);', [],
                function (transaction, resultSet) {
                    if (!resultSet.rowsAffected) {
                        // Previous insert failed.
                        alert('No rows affected!');
                        return false;
                    }
                    alert('insert ID was '+resultSet.insertId);

                    //Assign signed in user to global var
                    window.currentSignedInUserId = resultSet.insertId;
                });
            }               
        );

        // Redirect to home/listings page
        $.mobile.changePage( "#home", { 
            reloadPage: true,
            transition: "slidefade"} );

    }
}

$('#login').live('pageshow', function(event) {

    console.log(window.currentSignedInUserId); // This is empty - global var not working

    // Should this be tap??????? Find out. -----------
    $('a#signIn').click(function() {

        // Get values of all fields & buld vars
        var username = $('#login-username');
        var password = $('#login-password');

        // Check if fields are empty
        if( !username.val() ) {
              username.addClass('empty');
              $('label.login-username').addClass('blank');
            }
            if( !password.val() ) {
              password.addClass('empty');
              $('label.login-password').addClass('blank');
            }

            // If both not empty, check if user exists, if so sql update if not sql insert
            if (username.val() && password.val()) {

                // Get username
                usernameValue = username.val();

                // Run function
                doesSigningInUserAlreadyExistQuery(db);

            }

    });
});


$('#home').live('pageshow', function(event) {

    console.log("Page show fired on recordings page");

    db.transaction(getRecordingsQuery, getRecordingsDataHandler, errorHandler);

            // get stuff, loop through it and append

        // Refresh the list to add JQM styles etc
        $('#recordings-list').listview('refresh');

    }

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:08:33+00:00Added an answer on June 14, 2026 at 3:08 am

    I’ve managed to resolve it, its not really a proper fix but it works at the expense of a screen flicker whilst the screen refreshes.

    If it helps anyone, I added allowSamePageTransitions: true which solved the issue (at the expense of a flicker).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I am writing an app with both english and french support. The app requests
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.