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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:48:14+00:00 2026-05-29T03:48:14+00:00

I use the following code to query my websql database to see if there

  • 0

I use the following code to query my websql database to see if there are any records.

If records are found then I use an ajax request to submit these to an asp page which in turn pushes the form information on to a sql server.

So far everything is good however I now want to delete each of the records from the WebSql database only when the ajax request returns a success.

I can’t for the life of me get my head around javascript functions and scope correctly when they are nested this big (i’ve only been writing js/jquery now for a couple of weeks).

I know I need to capture the ID which I have set as a variable vID an then execute another sql statement to delete the record, nested within the success criteria of my ajax call. I cant get vID to reference correctly and then I do not know how to set up the call to execute the sql again based on this.

function Web_SQL_Storage_Open_And_Check() {
    if (window.openDatabase) {
        var db = openDatabase("ER_Nonconformance", "1.0", "Non-conformance Report DB", 4 * 1024 * 1024); //creates our database if it does not exist at 4mb size
        var db2 = db.transaction(function(tx) {
          tx.executeSql("CREATE TABLE IF NOT EXISTS tbllog (ID INTEGER PRIMARY KEY ASC AUTOINCREMENT, DteOccur datetime, Pdetected nvarchar(50), DeptRaisedBy int, DeptResp int, NCDescrip nvarchar(255), NCCause nvarchar(255), NCImmediateAct nvarchar(255), NCLocation nvarchar(100), PNumOrRef nvarchar(30), EventCat int, ReportedEmailAddy nvarchar(100), Location_Category int)");
          tx.executeSql("SELECT * FROM tbllog", [], function(tx, result) {


                                if (result.rows.length > 0) {

                                alert("we need to submit")
                                for (var i = 0; i < result.rows.length; i++) {
                                //Submit values to the asp page using the below loop
                                var vID = (result.rows.item(i)['ID'])
                                var vPdetected = result.rows.item(i)['Pdetected']
                                var vDteOccur = result.rows.item(i)['DteOccur']
                                var vDeptRaisedBy = result.rows.item(i)['DeptRaisedBy']
                                var vDeptResp = result.rows.item(i)['DeptResp']
                                var vNCDescrip = result.rows.item(i)['NCDescrip']
                                var vNCCause = result.rows.item(i)['NCCause']
                                var vNCImmediateAct = result.rows.item(i)['NCImmediateAct']
                                var vNCLocation = result.rows.item(i)['NCLocation']
                                var vPNumOrRef = result.rows.item(i)['PNumOrRef']
                                var vEventCat = result.rows.item(i)['EventCat']
                                var vReportedEmailAddy = result.rows.item(i)['ReportedEmailAddy']
                                var vLocation_Category = result.rows.item(i)['Location_Category']

                                var request = $.ajax({
                                url: "untitled.asp",
                                type: "post",
                                data: {
                                DteOccur: vDteOccur,
                                Pdetected: vPdetected,
                                DeptRaisedBy: vDeptRaisedBy,
                                DeptResp: vDeptResp,
                                NCDescrip: vNCDescrip,
                                NCCause: vNCCause,
                                NCImmediateAct: vNCImmediateAct,
                                NCLocation: vNCLocation,
                                PNumOrRef: vPNumOrRef,
                                EventCat: vEventCat,
                                ReportedEmailAddy: vReportedEmailAddy,
                                Location_Category: vLocation_Category
                                },
                                dataType: "html"

                                }

                                );

                                request.done(function() { alert("done"); })
                                request.fail(function() { alert("error"); })
                                request.always(function() { alert("complete"); });


                                }



                                } 
                                else {
                                //no records found so do nothing
                                alert("do nothing")
                                } //end of if statement

            }, function(tx, error) {
                alert("error retrieving")
            })




          //tx.executeSql();


        });
    }

}
  • 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-29T03:48:14+00:00Added an answer on May 29, 2026 at 3:48 am

    Define var vID outside function, not inside and that gives you the correct reference.

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

Sidebar

Related Questions

For example, if i use following code to query some data from database. Uri
I use the following code: - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {
I use the following code to remove all KlientDoTrasa assigned to trasaOriginal and then
I use the following code to only read the database.... NSString *databasePath = [[[NSBundle
I use the following code to display list of contacts, and then retrieve contact
I use the following code but the it doesnot return any thing, declare @test
The following code: jQuery(document).ready(function($) { function getBooks() { var query = ajax.php?do=allbooks; $.ajax({ dataType:
I use the following code to create countdowns in Javascript. n is the number
I use the following code to compile a cpp file to object file. g++
I use the following code try to create an array of string vectors, I

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.