Adding information into sqlite from a json document

There seems to be an issue here, I'm unable to make an insertion:

 $.getJSON('file.json', function(data) {   

 tx.executeSql("INSERT INTO table (DATE, LIB, BID) VALUES("+data.date+","+data.Lib+","+data.BID+")");

      });

Answer №1

Remember to enclose string data in quotes when inserting.

"INSERT INTO table (DATE, LIB, BID) VALUES('"+data.date+"','"+data.Lib+"','"+data.BID+"')"

An even better approach:

tx.executeSql("INSERT INTO table (DATE, LIB, BID) VALUES(?,?,?)", [data.date, data.Lib, data.BID]);

Answer №2

After attempting this code and finding it unsuccessful in executing the query within the function(data)

I discovered that placing the query both before and after the function resulted in success

Ultimately, I had to transfer data to another function in order to execute the query

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

Performing a PHP Curl request and an ajax query to an ASP.NET page

I am attempting to send an ajax query to an ASP.NET page. Here is the algorithm I am following: 1. There is a form on my webpage; 2. When the user fills in all the fields, they click the submit button; 3. Upon clicking the submit button, JavaScript sends ...

Error: props.addPost does not exist as a function

Help Needed with React Error: props.addPost is not a function. I am trying to add a new post in my app. Please assist me. import React from "react"; import classes from "./MyPosts.module.css"; import { Post } from "./Post/Post.jsx& ...

Provide a unique <li> attribute for the JavaScript function to utilize

Is there a way to pass specific attributes from dropdown options to a javascript function? I have tried using .data() and .attr(), but the console keeps showing "undefined". Any suggestions on how to achieve this in a cleaner and simpler way would be gre ...

Display information from an array in checkboxes. If the same data appears in another array, the corresponding checkbox in React will be automatically checked

I currently have two arrays. The first array, let's call it arr1, contains multiple objects such as [{"Name":"Mr.X"},{"Name":"Mr.Y"},{"Name":"Mr.Z"}]. The second array, named arr2, holds a few values like [{"Name":"Mr.Z"}]. My goal is to display all ...

Reinitializing the CanvasRenderingContext2D transform with resetTransform and harnessing the power

I've encountered an unexpected issue with the Google Closure Compiler in ADVANCED mode, and I'm struggling to understand it: it's renaming the function resetTransform of CanvasRenderingContext2D Unfortunately, I can't directly share th ...

How can I extract a list of names from an array of dictionaries in iOS programming?

I am currently attempting to retrieve objects from a file on the server: NSURLSession *session = [NSURLSession sharedSession]; NSString *string = @"http://myfile.php"; //NSLog(string); //CHECK [[session dataTaskWithURL:[NSURL URLWithString:string] ...

Mastering the Art of Accessing Specific Data from JSON Files in C# [Accomplished]

I'm relatively new to development so please be patient with me. I have a task where I need to parse multiple JSON files (around 74) that all contain different values. How can I efficiently read these JSON files dynamically and extract specific values ...

Contrasting the use of jQuery versus AJAX for updating static page text

While I haven't fully grasped the concept of AJAX yet, my understanding is that it can be beneficial for updating specific parts of a webpage. Does using AJAX only make sense when you require server interaction? I am looking to replace text on a webp ...

How to translate a list of integers into JSON format using Java

Can someone help me with converting an array of integers into JSON format? The array is created in Java and I need it in the form of a JSONArray or JSONObject. Here's my code: int[] tableau = new int[6]; JSONArray jsonArray = new JSONArray(); int k ...

What is the best way to send a parameter to the callback function of a jQuery ajax request?

I am facing an issue where I need to pass additional variables to a jQuery ajax callback function. Consider the following scenario: while (K--) { $.get ( "BaseURL" + K, function (zData, K) {ProcessData (zData, K); } ); } func ...

Converting Whatsapp chat history into a dialogue in JSON format

There's an interesting challenge with parsing a Whatsapp log file into a JSON format. The timestamps are not accurate, but the goal is to split each message into three parts: time (as a timestamp), name of the person, and the message content. In addit ...

Failure to trigger the success action in ExtJS

I am currently utilizing struts2 for the server-side implementation combined with ExtJS4 for the user interface. I have a basic form that I submit to the server, but the response consistently goes to the failure case of the request even though I am just re ...

Creating a dedicated subfolder for 4 REST API routes for better organization

I'm struggling to figure out why my .get('/:post_id') route isn't working... My project's folder structure looks like this: app.js routes --api ----blog.js The blog.js file is located in the routes/api folder. In app.js, I&apo ...

The icons from MaterializeCSS are not displaying correctly on the navbar within an Angular 7 project

Having an issue implementing MaterializeCSS Icons on the navbar. The arrow-drop_down icon is not displaying correctly, showing only text instead. Oddly enough, the icons render properly on other pages except for the app.component.html file. I attempted to ...

Troubleshooting the issue of inadequate bytes while parsing JSON in Yesod

Currently, I am attempting to extract the response body of a Json POST request using this Yesod code snippet: import qualified Data.Aeson as J postMypageR = do json <- parseJsonBody :: Handler (J.Result J.Value) case json of J.Error e -> ...

I'm running into an InvalidSelectorError and I could use some assistance in properly defining

As I gaze upon a massive dom tree, my task using NodeJS/Selenium is to locate an element by the title attribute within an anchor tag and then click on the associated href. Despite being a newcomer to regex, I am encountering numerous errors already. Below ...

Having trouble activating the submit function using an external JavaScript file

Having trouble getting the form to submit properly. I have placed the form inside a <div id="access"></div> by setting its innerHTML using an included js file in the header of the page. Here's how it looks: <div id="access"> < ...

Incorporate personalized buttons into the header navigation for each view using VueJS

In my VueJS project, I attempted to include custom buttons in the sub navigation menu which could be customized for each view. Initially, I tried adding a simple property to the main data element, but that didn't yield the desired results. Then, I cam ...

The proper technique for invoking a class method within a callback [prototype]

I am currently working with prototype 1.7 and developing a class that is designed to take a list of divs and create a tab interface. var customTabs = Class.create({ initialize: function(container, options) { this.options = Object.extend({ ...

Tips for wrapping a div around its floated children

I'm currently developing a website for an online shopping cart and working on making the search results responsive. I am aiming to display as many items as possible across the screen (usually 3) when viewed on any device with a resolution lower than t ...