Html5 declares that the statuses of values are not defined

In a chrome extension, I am encountering an issue with the following code:

var DB = openDatabase('CMPDB', '1.0', 'Database for CMP', 4 * 1024 * 1024); 
LoadFromDB();   

function LoadFromDB() {

    DB.transaction( function(tx)
    {           
        tx.executeSql('CREATE TABLE IF NOT EXISTS table(X, Y, Z UNIQUE)');

        tx.executeSql('SELECT * FROM table', [], function (tx, results) {
            var len = results.rows.length;
            for (i = 0; i < len; i++) {                 
                alert(results.rows.item(i).X.text);
                alert(results.rows.item(i).Y.text);
                alert(results.rows.item(i).Z.text);                         

            }
        });
    });
}

I'm puzzled as to why all of the alerts are returning undefined even though the table has been created beforehand and the Chrome Dev tools show that values exist in the table. Any insights on this perplexing situation?

Answer №1

It seems that your SELECT statement may be running before the table is fully created. You could consider placing your SELECT query inside a callback function to ensure it is executed after the CREATE TABLE SQL command has finished. Here's an example:

tx.executeSql('CREATE TABLE IF NOT EXISTS table(A, B, C)', function(tx) {
    tx.executeSql('SELECT * FROM table', [], function (tx, results) {
        var length = results.rows.length;
        for (index = 0; index < length; index++) {                 
            console.log(results.rows.item(index).A.text);
            console.log(results.rows.item(index).B.text);
            console.log(results.rows.item(index).C.text);                         
        }
    });            
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to resolve the issue of Duplicate keys detected with value '0'. This could potentially lead to errors during updates

Encountered a warning in Vue js stating 'Duplicate keys detected: '0'. This warning could potentially lead to an update error. To resolve this issue, I utilized the getter and setter in the computed variable and dispatched the value to Vuex ...

What is the best way to fetch a partial JSON response object from an API using JavaScript?

Currently, I am utilizing the One Bus Away API, returning a response object in this format: { "code": 200, "currentTime": 1504150060044, "data": { "entry": { "arrivalsAndDepartures": [ {AnD_item1 ...

Encountering a 'unknown column' error while using MySQL on a Windows operating system

A query is being executed on Node.Js with MySQL, resulting in the following: SELECT COUNT(DISTINCT t.uid) AS usersCount, COUNT(*) AS workingDaysCount FROM ( SELECT d.date, u.id AS uid, CASE TIMESTAMPDIFF(day, SUBDATE(d.date, WEEKDAY(d.date) ...

Collect user input from an array of checkboxes

After spending hours attempting to retrieve data from an array of checkboxes with the same name, I am still facing difficulties. <input type="checkbox" name="node"/> var selectedValues = []; $(document.getElementsByName("node")).each( ...

Using Javascript to initialize events based on a variable

This particular plugin is structured in the following way: (function($){ var defaults = { param1:null, param2:null }; var methods = { init:function(params) { var ...

"Cookie Magic: Unleashing the Power of Ajax and

I am currently working on an ASP.NET 3.5sp1 application with a single page layout where all interactions are handled through ajax, eliminating the need for postbacks. The website in question is . This app does not require user accounts and allows anonymou ...

Tips for loading a webpage directly to the center instead of the top position

Is there a way to make the page open at a specific div halfway down the page instead of starting from the top? Here is an example: <div id="d1"> <div id="d2"> <div id="d3"> <div id="d4"> <div id="d5"> <div id="d6"> Do ...

Updating interval time based on an external variable with jQuery

I have developed a JavaScript script where pressing a button triggers the continuous playback of an audio file. The audio, which is a 'beep' sound, serves as an alarm. The frequency at which the beep plays is determined by a setting located on a ...

Unable to transmit an object containing a property that includes an array of other objects

I am attempting to send an object that has the following structure: var postBody = { id: userID, objectID: [0, 1], objects: [ {id: 0, x: 0.33930041152263374, y: 0.08145246913580247, width: 0.0823045267489712, height: 0. ...

What is the best way to utilize the isset method in PHP to check for the existence of two different

Having trouble with displaying both data sets in a PHP file? Here's the code snippet: <?php session_start(); include_once'config/connect.php'; //establish database connection if(isset($_POST['add'])) { $add = mysql_query( ...

javascript The event handler is not functioning properly for the dynamically loaded AJAX content

I am facing an issue with adding a JavaScript event listener to a dynamically loaded div via AJAX. Below is my code snippet: var QuantityMiniCart = function() { var infor = document.querySelectorAll( '.mini-cart-product-infor' ); if ( ...

What is the most effective and secure method for inserting data into MySQL or SQL databases using Node.js?

For my Nodejs and Express project, I am torn between two methods of storing data. I am uncertain which one is both better and more secure. Method 1: var insertQuery = "INSERT INTO mytable (value1,value2) values (?, ?)"; con.query(insertQuery, [value1,val ...

Creating a horizontal scrolling section for mobile devices using CSS

Looking to create a horizontal scroll area specifically for mobile devices, similar to the design seen here: https://i.sstatic.net/oSNqL.png Additionally, I want to hide the scrollbar altogether. However, when attempting to implement this, there seem to ...

Verify authentication on a SignalR console application using a JavaScript client

Here is the scenario and solution I am currently working on: In project one, I have a SignalR console application that handles the logic, including authentication using Entity Framework to query the database. In project two, I have an ASP.Net web applicat ...

Dynamically taking input in Vue JS while using v-for loop

Hey there! I'm trying to get input in this specific manner: itemPrices: [{regionId: "A", price: "200"},{regionId: "B", price: "100"}] Whenever the user clicks on the add button, new input fields should be added ...

Tips for incorporating a favicon in a React application

Having trouble adding a favicon to my React application. I followed the instructions in this post, but it's not working for me. I placed the favicon.ico file inside the public folder where index.html resides. This is how my directory structure looks ...

Incorporating CouchDB storage into a Node.js socket.io JSON data stream

Currently in the process of researching how to implement persistence for a real-time Twitter JSON feed in Node.js. The stream is set up and sending data to the client, but I'm struggling with storing this information in a CouchDB database so that it c ...

Access view name in controller using Ui-Router

Utilizing the ui-router in AngularJS allows for the implementation of multiple views within the same page/state. While each view consists of a template, controller, and more, there appears to be no straightforward method of assigning a "resolve" function ...

Learn the method of showcasing a JavaScript variable value within an HTML href tag

Currently, I am in the process of rewriting my URL and category name to be passed into the URL. For this purpose, I am creating a URL friendly string using the following JavaScript function: function getUrlFriendlyString(str) { // convert spaces to &ap ...

Determine using Javascript or jQuery whether the value of input1 is greater than the value of input2

Ensuring that Value1 is always greater than Value2 in a form submission is crucial. If Value1 becomes greater than or equal to Value2, an error message should be displayed and the form submission should not be processed. Below is the code for the form: & ...