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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:21:37+00:00 2026-06-15T10:21:37+00:00

the simplest example of what I’m looking for is this: var messageLoader = $.post(api/user/messages,

  • 0

the simplest example of what I’m looking for is this:

var messageLoader = $.post("api/user/messages", {api:data})

messageLoader.done(function(data){
   //do something 
});

This works brilliantly, but only once. If I want to update the data, I have to redefine everything.

I can’t seem to find any call for the Deferred Object that let’s me restart it. i.e. messageLoader.redo(), which ideally would re-do the POST request, and subsequently call the same “done” handler without me having to re-define it.

I could put it all in a function and simply call that function again, but that’s not what I’m looking for, because I would further want to do this:

var messageLoader = $.post("api/user/messages", {api:data})
var friendRequestLoader = $.post("api/user/friendrequests", {api:data})

$.when(messagesLoader, friendRequestLoader)
    .done(function (messages, friendRequests) {
        // update display of messages and friend requests
        // attach Handlers
    });

$("#updateMessages").click(function(){
    messageLoader.redo() // This doesn't exist
})

The idea is that clicking $("#updateMessages") would re-do just that request, then the $.when() handler would use the new messageLoader data, and the original friendRequestLoader data.

I’ve looked in the docs for something like this but haven’t found anything. Perhaps someone here knows if it exists, or a way to accomplish the same thing.

  • 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-15T10:21:38+00:00Added an answer on June 15, 2026 at 10:21 am

    I’m pretty sure the Deferred class just isn’t designed to work the way you want, because they’re intended to be one-time use objects. I even sat in on a whole session on Deferreds at jQueryConf, and re-using them wasn’t even mentioned.

    Furthermore, as you can see from the Deferred API page:

    http://api.jquery.com/category/deferred-object/
    

    there is no restart method. You might be able to manually change the properties of a Deferred to simulate “restarting” it, but really I think you should make your own class at this point, as you’re really looking for something Deferred doesn’t offer.

    You have to keep in mind, Deferred is designed so that you can say “hey Deferred, go do something” (new Deferred().when(something)), and then you can say “hey Deferred, when that’s done do X” (deferred.then(x)). Now, when you say “when that’s done”, ie. when you make a .then call, the Deferred can be in two states: done, or not, but the call works in either case (if it’s done it resolves immediately, otherwise it waits to be triggered).

    Now, if a Deferred could have a third state (“done but restarted”), the .then call wouldn’t know what to do: does “done but restarted” mean that it should fire it’s thens, or not? The answer depends on whether you made the .then call before or after the restart call, and as you’re hopefully seeing that all has the potential to get rather complicated (especially if you allow for multiple restarts).

    Rather than deal with all that (none of which was needed for $.ajax) the jQuery folks went with the (comparatively simple) current Deferred implementation, and I think it was the right call on their part.

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

Sidebar

Related Questions

can anybody post the simplest possible example for django-ajax-selects ? Just one model with
Can someone post the simplest example on how to use controlTextDidChange with a text
All, I have what i think is the simplest example possible of data binding
The simplest example is when the user clicks submit, I want to show a
I'm new to basecamp api, and while trying out the simplest example: curl -u
This is the simplest example I could come up with that reproduces the problem.
I am looking for the simplest example which shows one window opening another window
This seems like a very simple and a very common problem. The simplest example
The simplest example would be the built in class keyValuePair(of T,U). I would like
The simplest example that I can provide for what I want to do is

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.