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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:25:25+00:00 2026-05-23T00:25:25+00:00

I’ve started using HTML5 and WebSQL, and I quickly ran into a problem: all

  • 0

I’ve started using HTML5 and WebSQL, and I quickly ran into a problem: all the DB calls are asynchronous.
I come from PHP programming, where all the calls are synchronous, and I’m at a loss with the asynch stuff.

Basically, I open the DB and run a query, which uses an id parameter I’m passing to the page via GET (i.e. http://myserver.com/mypage.html?id=123). I need the result in globalResult:

id=window.location.search.substring(1).split('=')[1];
db=openDatabase("testDB", "1.0", "Test Database", 10000000);

db.transaction(function(tx)
{
    tx.executeSql("SELECT * FROM testTable WHERE id="+id,[],successCB,errorCB);
});

function errorCB(tx,err)
{
    alert("Error processing SQL: "+err);
}

function successCB(tx,result)
{
    globalResult=result.rows.item(0)['description'];
}

...Javascript code which needs globalResult to be set...

Now, as the query is asynchronous, the interpreter starts executing the rest of the code before having the results, and of course it doesn’t work.

Is there any trick to run queries synchronously, or some technique to play with the callback functions in order to solve this problem?

Thanks in advance, guys 🙂

  • 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-23T00:25:25+00:00Added an answer on May 23, 2026 at 12:25 am

    In the end, the easiest solution I found was to change the flow of the Javascript.
    Instead of waiting for the results to populate my page (PHP-like), I went for a blank structure which gets populated in the end by the “success” callback function.

    Also, I recommend using jquery-sql, which greatly simplifies the code when it comes to WebSQL.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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
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.