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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:22:12+00:00 2026-05-18T00:22:12+00:00

First I know WebKit do not allow Make synchronous requests to SQLite database. And

  • 0

First I know WebKit do not allow Make synchronous requests to SQLite database. And I’m start playing with it and tried to assign result to global variable “data”. I still not sure if it’s possible but want to ask you.

  1. I’m created global object to store respond from DB

    var data = {};
  2. Here is DB class


var db = {
        mydb: false,
        init: function () {
            try { 
                if (!window.openDatabase) { 
                    alert('not supported'); 
                } else { 
                    this.mydb = openDatabase('test_db', '1.0', 'Test DB', 1024*1024*5); 
                }
            } catch(e) { 
                // Error handling code goes here. 
                if (e == INVALID_STATE_ERR) { 
                    // Version number mismatch. 
                    alert('Invalid database version.'); 
                } else { 
                    alert('Unknown error '+e+'.'); 
                } 
                return; 
            }
        },
        exec: function (query, params) {
            try {
                this.mydb.transaction(function(transaction) {
                    transaction.executeSql(query, params, db.dataHandler, db.errorHandler);
                });
            } catch(e) {
                alert(e.message);
            }
        },
        dataHandler: function (transaction, results) {
            // Handle the results
            data = results.rows;
            return true;    
        },
        errorHandler: function (transaction, error) {
            // returns true to rollback the transaction
            alert('Code: '+error.code+'\nMessage: '+error.message);
            return true;
        },
    }
  1. And finally here is the problem:

$(function () {
    db.init();
    db.exec('SELECT * FROM errors;');
    alert(Log.object_toString(data) ); // this alert show empty object as I declared in first line 
    alert(Log.object_toString(data) ); // this one return object with responded data from database
});

So the problem is I can’t manipulate with “data” right after db.exec() call, but if I make alert() after transaction then data will populate with all information.

Any ideas how can I avoid it?

  • 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-05-18T00:22:13+00:00Added an answer on May 18, 2026 at 12:22 am

    I would assume that you’re making an asynchronous AJAX call, so your alert() fires before the response is received.

    EDIT: As @Nick noted, this is not AJAX, but is an issue with it being asynchronous.

    I don’t know anything about the API you’re using, but it would seem as though your alerts should be inside the dataHandler method:

    dataHandler: function (transaction, results) {
        // Handle the results
        data = results.rows;
        alert(Log.object_toString(data) ); 
        alert(Log.object_toString(data) );
        return true;    
    },
    

    Or should be in some other function that is called from inside dataHandler.

    dataHandler: function (transaction, results) {
        // Handle the results
        data = results.rows;
        someFunction( data );
        return true;    
    },
    
    // ...
    
    function someFunction( data ) {
        alert(Log.object_toString(data) ); 
        alert(Log.object_toString(data) );
    }
    

    The reason an alert() in between makes it work, is that the pause gives the response a chance to return before the other alerts run.

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

Sidebar

Related Questions

Let me state first: I know that any user that wants to run a
I know at first glance (due to the title) this looks like one of
first time SO user :) I know that I can format a number like
First of all, I know how to build a Java application. But I have
First, yes I know about this question , but I'm looking for a bit
First off, I know next to nothing about language theory, and I barely know
I know that I need to tell my UITextField to resign first responder when
First, I know there are methods off of the generic List<> class already in
First, I know about this: How would you organize a Subversion repository for in
First question on here so please be nice :) I know very little about

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.