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

  • Home
  • SEARCH
  • 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 8472761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:09:54+00:00 2026-06-10T17:09:54+00:00

I’m setting up a mobile app with jQuery Mobile and PhoneGap. What I want

  • 0

I’m setting up a mobile app with jQuery Mobile and PhoneGap. What I want to do is that when I click link with id “news_link” I want jQuery to fetch data from database and put it to jQm’s collapsible set. In my solution, I’ve wanted to use $.mobile.changePage inside callback functions because I want to wait until the data has been fetched and put inside the container before the code changes page.
Here’s the code:

$(function() { 
  $('#news_link').click(function(){
    loadNewsFromDB(function(){
       $.mobile.changePage( $("#news"), { transition: "slideup"} );
    });
});

loadNewsFromDB is PhoneGap’s SQLite database function which would fetch the data with more callback functions from database. The contents would be put to desired container with .html-function

function loadNewsFromDB(){
//some code here
theDB.transaction(function(tx) {
    tx.executeSql(sqlStr, [], onLoadNewsSuccess, onLoadNewsError);
},onTxError, onTxSuccess);

function onLoadNewsSuccess(tx, results){
    //some code here
    $("#newsSet").html(htmlCodeAndContentToPut);

Html is jQm’s basic ui-modules:

<!-- some html code here --!>
<div data-role="page" id="news">
    <div data-role="content">
        <div id="newsSet" data-role="collapsible-set" data-mini="true">

With debugging I know that the code work up until it works very well unti it arrives to $.mobile.changePage-function. Somehow it doesn’t change the page. I’ve checked the function it works well in other occasions, but not inside callback-functions.

I would be very grateful if someone would give me a hand am I not seeing something obviously wrong or is something more specific? What other workarounds there is for fetching the data from SQLite, waiting for data to be fetched, putting the data to container and then changing the pages?

  • 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-10T17:09:56+00:00Added an answer on June 10, 2026 at 5:09 pm
    • I never had problems with $.mobile.changePage on callback-function
      from Ajax, so it is possible to change page from a
      callback-function
    • You call the loadNewsFromDB function with a function as a
      parameter.
      But I can’t see where/how you are using this parameter
      on the loadNewsFromDB function itself. Don’t you have to define the
      parameter on the loadNewsFromDB function?
      After defining the callback-function, you should call it when your data is ready.
    • I would try to use the $.mobile.changePage directly in your onLoadNewsSuccess function.

    I believe that the code should look like this:

    function loadNewsFromDB(callback){
    //some code here
    theDB.transaction(function(tx) {
        tx.executeSql(sqlStr, [], function(tx, result) {
                ...some code here...;
                if (callback) {
                    callback();
                }    
            },onLoadNewsError);
    },onTxError, onTxSuccess);
    

    Edit:
    To answer the question in the comments:

    • In your $(function() code, you are adding listener for the
      $('#news_link').click event.
    • In this listener, you tell Jquery to call loadNewsFromDB function and
      to send it the following callback-function as a parameter: function(){ $.mobile.changePage( $("#news"), { transition: "slideup"}.

    Sending the callback function is not enough, you should use it (call it) in your code.
    To use it, I did the following:

    • Changed the function definition function loadNewsFromDB(callback)
      now, it does have a new paramter: callback (which is the name you can use to call back your callback-function).

    • In your loadNewsFromDB function, you are calling the
      transaction function, and send it 3 parameters: inline function, onTxError, onTxSuccess.
      your inline function just call the tx.executeSql function and send it 4 parameters: sqlStr, [], onLoadNewsSuccess, onLoadNewsError.
      I changed the third parameter.
      Instead of calling the onLoadNewsSuccess function, I wrote the needed function inline

    • In the inline function, I checked if the callback function exist if (callback)
      If it exist, I called it! callback();
      calling the callback function, should change the page…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I have a view passing on information from a database: def serve_article(request, id): served_article
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.