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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:48:05+00:00 2026-06-15T00:48:05+00:00

I have a JavaScript bootstrapper module that I’m trying to keep very clean and

  • 0

I have a JavaScript bootstrapper module that I’m trying to keep very clean and simnple: Currently I have code like:

function bootStrapper() {
       xmlRepository.getAll().done(function (result) {
       autoPolicyForm.show();       
   });
}

In xmlRepository I am using a deferred object within getAll();

function getAll () {
    var d = $.Deferred();

    $.ajax({
        type: "GET",
        url: "http://localhost/Autopolicy/dataSource.xml",
        dataType: "xml",
        success: function (xml) {
            d.resolve(xml);
        }
    });

    return d.promise();
}

This code is working well but I would really like to simplify the bootstrapper code further to something like:

function bootStrapper() {
       var result = xmlRepository.getAll();
       autoPolicyForm.show();       
   });
}

Everything I try results in ‘result’ being undefined due to the async nature of call.

Does anyone know how to modify the code to move the complexity to the xmlRepository so that the above can be achieved?

Thanks

  • 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-15T00:48:07+00:00Added an answer on June 15, 2026 at 12:48 am

    In modern jQuery the ajax function returns a promise so you can simplify getAll to :

    function getAll () {
        return $.ajax({
            type: "GET",
            url: "http://localhost/Autopolicy/dataSource.xml",
            dataType: "xml"
        });
    }
    

    In other words it is now possible to do

    $.ajax(url).done(function(xml){...});
    

    You could also change getAll to

       function fetchAll (callback) {
            $.ajax({
                type: "GET",
                url: "http://localhost/Autopolicy/dataSource.xml",
                dataType: "xml"
            }).done(callback);
        }
    

    So you’ll do

       xmlRepository.fetchAll(function (result) {
           autoPolicyForm.show(); 
       });
    

    But apart setting async to false, you can’t avoid passing a function as the execution is asynchronous. And you should consider that a javascript application is naturally event based so it’s fine for the users of an API to use and pass anonymous functions (callbacks).

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

Sidebar

Related Questions

i have javascript code that looks like this: $('#lnkPopup').click(function() { var id = $(this).attr('rel');
I have JavaScript code like this: var buffer=new Array(); function fetchData(min,max){ var ajaxReq =
I have JavaScript that basically looks like the following function a() { b(1); }
I have javascript code like below - function initPage(){ // Left Navigation Pane -
I have javascript code that i am trying to mimic in an android application:
I have javascript code some thing like this -- var count=3; var pl=new Array(count);
I have JavaScript form validation functions like so: function validate_name(field) { if (field ==
I have javascript like and i want to set time delay to this function
I have javascript function (that uses Raphael) that on click select area. And I
I have javascript object defined like this: function SocialMiner() { var verbose=true; var profileArray=new

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.