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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:49:51+00:00 2026-06-09T07:49:51+00:00

I have not used deferreds before but I’ve read a bit here and there

  • 0

I have not used deferreds before but I’ve read a bit here and there on them and from my understanding, it sounds like they’d be a solution to a current problem I’m having. I have a page that has to load 4 ads on it. Previously the page was slowing down due to the time it would take the server to query the database for each ad. So I moved the banner ad calls to a web service. This worked fine however if I have no ads I need to hide the container div so that means I need to know when all the ajax calls have completed and then check to see if any ads were loaded.

I have the following code that successfully calls the web service and loads the ads but it doesn’t appear that the then() function is working right. It seems to be executing before the ajax calls complete. I got my code from this page JQuery deferred with .each() and the only difference I can see is that in their example, it shows returning the function call within the deferred. But I’ve tried surrounding my function innerds with return{} but it just throws an error (Unexpected token “=”). Can anyone tell me what I’m doing wrong? Thanks.

  var deferreds = $(".ad").map(function () {

    var t = $(this);

    $.ajax({
        type: "POST",
        url: "/Services/Services.asmx/GetBanner",
        data: "{'bannerId':" + t.attr("bannerid") + ",'siteId':" + sid + ",'dt':'" + new Date().toString() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json"
    })
    .success(function(data) {
        if (data.d.Banner != null && data.d.Banner != undefined) {
            t.html("<div class=\"featuredAd\">" + data.d.Banner + "</div>");
        }
    });
});

$.when.apply(null, deferreds.get()).then(function () {
    if($(".featuredAd").length > 0)
        $("#dvFeaturedBottom").show();
});
  • 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-09T07:49:52+00:00Added an answer on June 9, 2026 at 7:49 am

    You didn’t return the promise objects.

      var deferreds = $(".ad").map(function () {
    
        var t = $(this);
    
        return $.ajax({
            type: "POST",
            url: "/Services/Services.asmx/GetBanner",
            data: "{'bannerId':" + t.attr("bannerid") + ",'siteId':" + sid + ",'dt':'" + new Date().toString() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json"
        })
        .done(function(data) {
            if (data.d.Banner != null && data.d.Banner != undefined) {
                t.html("<div class=\"featuredAd\">" + data.d.Banner + "</div>");
            }
        });
    });
    
    $.when.apply($, deferreds.get()).then(function () {
        if($(".featuredAd").length > 0)
            $("#dvFeaturedBottom").show();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have not used PackedArray before, but just started looking at using them from
I have not used valgrind before, but I need to use it to check
I have not used ASP.NET Membership and Role Providers before but looking for a
I have not used MAC OSX before, but I wanted to buy one for
I have not used phing before, but would like to use it to automate
I'm a big fan of blocks, but have not used them for concurrency. After
I have not used many lambda expressions before and I ran into a case
Disclaimer: I have not used RoR, and I have not generated tests. But, I
I know system.exit(0) should not be used. I have read plenty of tutorials as
I have not used Junit before and have not done unit testing automatically. Scenario:

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.