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 8941645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:21:17+00:00 2026-06-15T11:21:17+00:00

I am having an issue with a project I am working on using phonegap

  • 0

I am having an issue with a project I am working on using phonegap

[Step 1] –
I am storing a users login “session” locally (Web SQL) from a web server. This is working fine, I can successfully connect to the web server, post the user login data, get a response from the server, create the local User database and store the user “session” value

[Step 2] – I then need to pass this “session” value back to the web server, and receive response data from the server. Again, this works as expected but the problem is, the callback function is being executed twice.

Step 2 is called when the user taps a button on the screen, and it doesn’t seem like the reason that Step 2 is being called twice if because phonegap is picking up the tap more than once, I have tried:

$(".yes_sync").live("tap", function(){
    console.log("tap!");
    ...

Which only logs a single tap event.

When the user taps I am calling:

var db = window.openDatabase("MVIdb", "1.0", "MVIsqlite", 200000);
db.transaction(getUserId, getUserIdFailed, getUserIdsSuccess);

The getUserId, getUserIdFailed and getUserIdsSuccess functions look like so:

function getUserId(tx){
    tx.executeSql("SELECT * FROM user WHERE id = '1'", [], getUserIdsSuccess,     getUserIdFailed);
}

function getUserIdFailed(tx, results){
    console.log("Error retrieving user session ID");
}

function getUserIdsSuccess(tx, results){
    console.log("Success retrieving user session ID");
    if(typeof results != 'undefined'){
        var return_value = results.rows.item(0).user_id; 
        user_session_id = return_value;
        var token = $.md5(user_session_id+"whatever!");

        $.get('http://localhost/project/dummyserver/sync?user_id=' + user_session_id + '&token=' + token, function(data) {  
            data = $.parseJSON(data);       
            for (var key in data){
                console.log(data[key]['user_id']);
            }

            $(".ui-loader").fadeOut();
            jQuery.mobile.changePage("_sync_complete.html", {  role: "dialog", transition: "pop" } );
        });
    }
}

As you can see, the last line in the callback for the $.get in the callback for the success opens a pop up dialogue. This dialogue is being called twice.

I have noticed that phonegap has a lot of asynchronous behaviour, which I understand is to prevent the system from feeling “laggy”, but surely it shouldn’t be executing a callback function on a db.transaction more than once?

  • 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-15T11:21:17+00:00Added an answer on June 15, 2026 at 11:21 am

    Not the most elegant solution, but I went with using a global variable

    var has_getUserIdsSuccess = false;
    

    And in the callback function:

    if(typeof results != 'undefined'){
        if (has_getUserIdsSuccess == false){ 
            has_getUserIdsSuccess = true;
            // as per above
            has_getUserIdsSuccess = false;  // set it back to false so use can press the execute this function again later
        }
    

    I am still interested to see if anyone has a better solution!

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

Sidebar

Related Questions

I am currently working on an android project and I am having an issue
I'm having an excessively strange issue. I'm working on a project and it's being
I'm having an issue calling a method from a separate project within the same
I'm having an issue with the Attrib task from the MSBuild Community Tasks Project
I am working on a project with dreamweaver CS 6, using the phonegap build
I'm working on a project using sparql & dbpedia. I 'm currently having an
I'm working on a project where I'm using RandomAccessFile. The biggest issue I am
I am using SignalR in an ASP.Net Web Application project and am having issues.
I'm having an issue with a WordPress theme project I'm working on (the theme
I'm having an issue with style inheritance on a project I'm working on at

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.