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

  • SEARCH
  • Home
  • 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 7980929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:13:12+00:00 2026-06-04T10:13:12+00:00

Apologies but I seem to be going round in circles. The process is fairly

  • 0

Apologies but I seem to be going round in circles.

The process is fairly staightforward

  1. SaveButtonClicked

  2. call function to perform offline db transaction to update a record

  3. check if online ( /*used the Ed Norton example for doing this */ )

  4. if online call select transaction to fetch all updated records

  5. success of select load results into an array

  6. call webservice with array

so far I’ve tried to control the flow with
$.Deferred, dothis = defer.pipe(…),
.queue [but these seem to based on an element rather than a function completing] ,
putting the functions into an array ,

in testing the console always writes the ‘array built’ before the ‘building array’

var arrvals = [];
var deferA , deferB;
function updatedb(params){
    db.transaction('update....',[params],updateOk,updateFail)
}
function updateOk(){
    deferA.resolve()
}
function updateFail(){
    deferA.reject()
}
function areweonline(){
    $.ajax(.....) 
}
function selectrows(){
    db.transaction('update....',[params],buildarray,selectFail)
}
function buildarray(transaction,results){
    console.log('building array')
    for(i=0;i<=results.rows.length;i++){
        var row = results.rows.item(i);
        var job = {};
        job.text = row["testtext"]
        arrvals.push(job);
    }
    deferB.resolve()
}
function selectFail(){
    deferB.reject();
}
function callwebservice(vals){
    $.ajax(....) /* this bit is working fine*/
}
function SaveButtonClicked(){
    deferA = $.Deferred(); 
    deferB = $.Deferred();
    $.when(deferA).then(
        console.log('update completed')
        $.when(deferB).then(function(){
            console.log('array built')
            callwebservice(arrvals)
        })
    )
}

So what would be the best approach? $.Deffered, queue, callback …dark magic?

  • 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-06-04T10:13:14+00:00Added an answer on June 4, 2026 at 10:13 am

    try in this way

    function updatedb(params) {
        var deferA     = $.Deferred(),
            updateOk   = function() { deferA.resolve(); },
            updateFail = function() { deferA.reject(); }
    
        db.transaction('update....',[params],updateOk,updateFail);
        return deferA.promise();
    }
    
    
    function selectrows() {
    
        var arrvals = [];
    
        var deferB     = $.Deferred(),
            buildarray = function (transaction, results) {
                console.log('building array')
                for(i = 0; i <= results.rows.length; i++){
                    var row = results.rows.item(i);
                    var job = {};
                    job.text = row["testtext"]
                    arrvals.push();
                }
                deferB.resolve(arrvals);
            },
            selectFail = function() {
                deferB.reject();
            };
    
        db.transaction('update....',[params],buildarray,selectFail);
        return deferB.promise();
    }
    
    
    function callwebservice(vals) { $.ajax(....) /* this bit is working fine*/ }
    
    
    function SaveButtonClicked(){
    
        $.when(updatedb('your params here')).then(
            console.log('update completed')
            $.when(selectrows()).then(function(arr){
                console.log('array built');
                callwebservice(arr)
            })
        )
    }
    

    Some thoughts

    • You have an empty push() on selectrows function (I think it’s not what you want, because arrvals is empty);
    • I refactored your code to use less global variables/function: deferred objects are now declared inside functions that return a promise;
    • arrvals is now defined in selectrows() function, and you can pass it when you resolve the deferred task;
    • areweonline() function was removed from my example (since you’re not using it anywhere in your snippet);
    • when() are now looking for promises (and not for deferred).

    Note: I didn’t tried to execute the code, but hope this helps anyway

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

Sidebar

Related Questions

Apologies if this has been posted elsewhere but I can't seem to find any
Apologies in advance if this is obvious, but I can't seem to find an
Apologies for this seemingly minor question, but I can't seem to find the answer
Apologies for not posting any code for this but all my efforts seem to
My apologies if my question is not well worded but I seem to have
Apologies, but I did ask this at the wordpress site but it doesn't seem
Apologies if this is a simple solution, but my brain doesnt seem to be
Apologies for this question but I am a bit of a noob with Delphi.
Apologies for the long winded title but looking for a solution to what might
Apologies if this was already asked but, I have had a look and can't

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.