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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:08:48+00:00 2026-06-03T23:08:48+00:00

I have been reading a lot about JQuery’s deferred object. And I can see

  • 0

I have been reading a lot about JQuery's deferred object. And I can see how it works to de-couple code. I wrote this orignally using Async.js but would was recommended to use promise.

Most examples I find just chain things to AJAX calls. I want to chain an async function but can’t figure out how to do it. I am retrieving a time from the database then using that time as a parameter in a url, finally I would then like to make a AJAX call.

This is where I’m at:

    var fetch = function (contactId, callback, errorCallback)
    {
        var buildPromise = new $.Deferred();

        var getLastImportTime = function ()
        {
            var querySuccess = function (tx, result)
            {
                buildPromise.resolve("7 oclock");
            };

            var queryError = function (tx, e)
            {
                buildPromise.reject("Error querying database");
            };

            database.open();
            database.query("SELECT EventImportTime FROM Contact WHERE Contact.Id = ?", [contactId], querySuccess, queryError);
        };

        var buildUrl = function (lastImportTime)
        {
            console.log("I do happen");
            var url = "http://";
            url += 'MobileGetChangedEvents.aspx?Reference=';
            url += '&LastImportTime=';
            url +=  lastImportTime;
            url += '&Format=JSON';
                            return url;

        };

        var makeRequest = function (url)
        {
            getJSON(url, callback, errorCallback)
        };

        $.when(getLastImportTime()).pipe(buildUrl).then(makeRequest);

Also my pipe methods seems to be called first :s

  • 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-03T23:08:49+00:00Added an answer on June 3, 2026 at 11:08 pm

    since you pass getLastImportTime function to when helper method, it should explicitly return a promise, (but in getLastImportTime() you are returning nothing and when() is expecting you to pass a promise) otherwise the helper could evaluate it as an immediate resolved (or rejected) promise.

    This could explain why it seems that function in pipe is executed before getLastImportTime()

    So try to change your function like so

    var getLastImportTime = function () {
       ...
       database.open();
       database.query("SELECT  ...");
    
       return buildPromise.promise();
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use jQuery. I have been reading a lot about selector performance and optimizing
I have been reading a lot about openFrameworks and Processing, But still can't make
I have been reading a lot about C++ casting and I am starting to
Lately I have been reading a lot of blog topics about big sites(facebook, twitter,
I have been reading a lot about how flash development/design had died, and as
I have been reading a lot about HTML 5 and some of the changes
I have been reading a lot about Double Buffering as I am working on
I have been reading a lot about how and why to use an MVC
I have been reading a lot about Ruby the past few days. Every SO
I have been reading a lot about dependency injection recently, and in theory it

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.