473,383 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Js/Ajax function problem

374 256MB
Hi All,

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.

Expand|Select|Wrap|Line Numbers
  1. function Web_SQL_Storage_Open_And_Check() {
  2.     if (window.openDatabase) {
  3.         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
  4.         var db2 = db.transaction(function(tx) {
  5.           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)");
  6.           tx.executeSql("SELECT * FROM tbllog", [], function(tx, result) {
  7.  
  8.  
  9.                                 if (result.rows.length > 0) {
  10.  
  11.                                 alert("we need to submit")
  12.                                 for (var i = 0; i < result.rows.length; i++) {
  13.                                 //Submit values to the asp page using the below loop
  14.                                 var vID = (result.rows.item(i)['ID'])
  15.                                 var vPdetected = result.rows.item(i)['Pdetected']
  16.                                 var vDteOccur = result.rows.item(i)['DteOccur']
  17.                                 var vDeptRaisedBy = result.rows.item(i)['DeptRaisedBy']
  18.                                 var vDeptResp = result.rows.item(i)['DeptResp']
  19.                                 var vNCDescrip = result.rows.item(i)['NCDescrip']
  20.                                 var vNCCause = result.rows.item(i)['NCCause']
  21.                                 var vNCImmediateAct = result.rows.item(i)['NCImmediateAct']
  22.                                 var vNCLocation = result.rows.item(i)['NCLocation']
  23.                                 var vPNumOrRef = result.rows.item(i)['PNumOrRef']
  24.                                 var vEventCat = result.rows.item(i)['EventCat']
  25.                                 var vReportedEmailAddy = result.rows.item(i)['ReportedEmailAddy']
  26.                                 var vLocation_Category = result.rows.item(i)['Location_Category']
  27.  
  28.                                 var request = $.ajax({
  29.                                 url: "untitled.asp",
  30.                                 type: "post",
  31.                                 data: {
  32.                                 DteOccur: vDteOccur,
  33.                                 Pdetected: vPdetected,
  34.                                 DeptRaisedBy: vDeptRaisedBy,
  35.                                 DeptResp: vDeptResp,
  36.                                 NCDescrip: vNCDescrip,
  37.                                 NCCause: vNCCause,
  38.                                 NCImmediateAct: vNCImmediateAct,
  39.                                 NCLocation: vNCLocation,
  40.                                 PNumOrRef: vPNumOrRef,
  41.                                 EventCat: vEventCat,
  42.                                 ReportedEmailAddy: vReportedEmailAddy,
  43.                                 Location_Category: vLocation_Category
  44.                                 },
  45.                                 dataType: "html"
  46.  
  47.                                 }
  48.  
  49.                                 );
  50.  
  51.                                 request.done(function() { alert("done"); })
  52.                                 request.fail(function() { alert("error"); })
  53.                                 request.always(function() { alert("complete"); });
  54.  
  55.  
  56.                                 }
  57.  
  58.  
  59.  
  60.                                 } 
  61.                                 else {
  62.                                 //no records found so do nothing
  63.                                 alert("do nothing")
  64.                                 } //end of if statement
  65.  
  66.             }, function(tx, error) {
  67.                 alert("error retrieving")
  68.             })
  69.  
  70.  
  71.  
  72.  
  73.           //tx.executeSql();
  74.  
  75.  
  76.         });
  77.     }
  78.  
  79. }
Jan 30 '12 #1
0 1184

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jamo | last post by:
Hi all, can anyone help with this problem. I want to call an Ajax function from a list menu *onchange*, my javascript is not good. Code below: Menu: <select name="menu1"...
2
by: jfaulky | last post by:
Hi all, I have a simply AJAX function that I pass a URL and it returns its contents to a <DIV id="mydivname"> area of my screen. All works fine when I manually enter:...
1
by: shivendravikramsingh | last post by:
hello friends, actually i have a problem in using conditional statement in ajax function i m tring to describe my problem properly,what i want when i select a value form a combo its vlue is passed...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
2
by: willl69 | last post by:
Hi All, Ive been having a problem of late with one of my sites that uses PHP5 / Ajax. The problem is that periodically the ajax functions lock up and it gets stuck in the loading phase of the...
3
by: willl69 | last post by:
Hi All, Ive been having a problem of late with one of my sites that uses PHP5 / Ajax. The problem is that periodically the ajax functions lock up and it gets stuck in the loading phase of the...
17
by: Shalini Bhalla | last post by:
i have 2 tables bank master and branch details having bankcode as a common feild . i have designed a form in which i am filtering branches according to a particular bank code using ajax ,...
8
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox"...
2
by: panos100m | last post by:
Hi on page load a javascript functions (timedCount()) is executed (timer) which executes another javascript function (ajax function:findprov(divtowrite) ) in turn this calls a php file to query a...
4
by: BaseballGraphs | last post by:
Hello, I am trying to update data on my webpage using AJAX. The idea is when a user clicks a checkbox the data will be updated. This is the code that I have so far: <script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.