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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:13:19+00:00 2026-06-17T14:13:19+00:00

This question isn’t exactly typescript related but without the context it would be unclear

  • 0

This question isn’t exactly typescript related but without the context it would be unclear why I would even require such behavior. Should be relatively straight forward to understand whether you know Typescript or not.

I have a dialog class implementation in Typescript that looks something like this (only showing relevant methods and fields):

class BaseDialog{
     ...
     public dialogEl: JQuery;


     public AjaxLoadContent(route: string) { 
        if (this.dialogEl !== undefined)
           this.dialogEl.load(route);
        return this;
    }

    public HtmlLoadContent(html: string) { 
        if (this.dialogEl !== undefined)
           this.dialogEl.empty().html(html);
        return this;
    }

    public Show() { 
        if (this.dialogEl !== undefined)
            this.dialogEl.dialog("open");
    }
    ...
} 

I’m returning this from AjaxLoadContent() and HtmlLoadContent() so that I can chain a call to Show() as follows:

var dialog = new BaseDialog();
dialog.AjaxLoadContent("/Account/Login").Show();  //Ajax call
dialog.HtmlLoadContent(someHtml).Show();          //Load from variable, no ajax call

I find this chaining syntax very clean and logical so I want to stick with it, however, in the ajax scenario, Show() gets called before ajax load() completes so the dialog opens, then there is a delay before the content appears. I can’t provide a callback to load() since I’d like to explicitly chain Show() onto the call instead of calling it internally…therefore, I need some kind of synchronous mechanism.

I’m now looking into Frame.js to accomplish this “synchronous” style without hanging the browser with something like $.ajaxSetup({async: false;}). Here is the answer I was hoping would work: https://stackoverflow.com/a/10365952

However, the following code still has the delay:

 public AjaxLoadContent(route: string) { 
        if (this.dialogEl !== undefined){
             var that = this;
             Frame(function (next) { 
                 $.get(route, next);
             });
             Frame(function (next, response) { 
                 that.dialogEl.html(response);   //Breakpoint 1
             });
             Frame.init();
             return this;                            //Breakpoint 2
        }    
    }

However this doesn’t seem to work as Breakpoint 2 gets hit first despite the explicit control flow I’ve defined. The Show() call happens immediately after return this (therefore loading a blank dialog), then finally that.jQueryDialog.html(response) gets called from the second Frame, loading the content after the dialog has already been shown (therefore still a delay).

How can I accomplish this synchronous behavior?

  • 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-17T14:13:20+00:00Added an answer on June 17, 2026 at 2:13 pm

    This is exactly (IMO) what JQueryDeferred is for. You can use that for all this without needing to add another dependency on Frame.js. The easiest way to do this would be to return a JQueryPromise from each Async method, like so:

    ///<reference path="./jquery.d.ts">
    
    class BaseDialog{
    
         public dialogEl: JQuery;
    
         public AjaxLoadContent(route: string):JQueryPromise { 
                var deferred = $.Deferred();
                if (this.dialogEl !== undefined)
                    this.dialogEl.load(route)
                        .done(() => deferred.resolve())
                        .fail(() => deferred.reject());
    
            return deferred.promise();
        }
    
        public HtmlLoadContent(html: string):void { 
            if (this.dialogEl !== undefined) {
                this.dialogEl.empty().html(html);
        }
    
        public Show():void { 
            if (this.dialogEl !== undefined)
                this.dialogEl.dialog("open");
        }
    } 
    
    var dialog = new BaseDialog();
    dialog.AjaxLoadContent("something")
        .done(() => dialog.Show());
    

    That’s not quite as clean an interface, but the alternative is to do some awfully clever coding whereby your class throws each Deferred into a FIFO queue, and each subsequent method waits on the previous Deferred in the queue before it starts executing. Certainly possible, and if you’re designing this API for significant external consumption, it might be worth doing. But if you’re just planning to use it for some internal project, it sounds like too much work and maintenance to me. (Just my opinion, of course :-).

    (Other problems with your proposed interface: (1) it doesn’t have any way of handling errors, analagous to the JQueryDeferred.fail() handler; and (2) it doesn’t have any way of doing any external processing in-between calls to your class. What if you wanted to do a transform on the content before you called the Show() method?)

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

Sidebar

Related Questions

I know this question isn't exactly a programming question, but it will affect how
this question isn't related to jQuery itself but I found a plugin named Metadata
I hope this question isn't too broad, but then again I would expect the
I know this question isn't directly programming related, but since I want to be
I hope this question isn't too open ended, but a nudge in the right
This isn't the best question ever, but since search engines feel the need to
This question isn't really for any specific technology but more of general developer question.
The title of this question isn't so clear, but the code and question is
Hopefully, this question isn't too juvenile to ask - but here goes: I'm trying
First I will give a little background info so this question isn't completely without

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.