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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:06:20+00:00 2026-06-17T08:06:20+00:00

Using callbacks, I have the following code var TK = { List: [], getSectionA:

  • 0

Using callbacks, I have the following code

var TK = {
    List: [],
    getSectionA: function(listName, callback)
    {
        var arrayList = [];
        $.get('ajax/test.html', {sendName: listName}, function(data) {

              $.each(data, function()
              {
                     arrayList = data;
              });
         callback(arrayList);
        });       

    }

};

calling the function

   $("#dropDownList").change(function()
   {
       TK.getSectionA(fileName, function(data)
       {
             TK.List = data;
             alert(TK.List); // This works ok...
       });

             alert(TK.List); // This does not work when calling using this property outside the callback..
   });  

How can I get this to work outside the callback function which is in another function

  • 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-17T08:06:21+00:00Added an answer on June 17, 2026 at 8:06 am

    the jQuery get() function returns the promise interface that allows you to add as many functions as you want to handle the get() completing either successfully (done()) or failing (fail) or just completing either way (always()).

    The promise interface is the same as the deferred but only has the “read only” methods so you can’t interfere with the process but you can see what happens.

    If you return the promise, it can be used to do whatever you want:

        var TK = {
            List: [],
            getSectionA: function(listName, callback)
            {
                var arrayList = [];
                return $.get('ajax/test.html', {sendName: listName}, function(data) {
    
                      $.each(data, function()
                      {
                             arrayList = data;
                      });
                 callback(arrayList);
                });       
    
            }
    
    };
    

    Call it something like this:

     TK.getSectionA(fileName, function(data)
           {
                 TK.List = data;
                 alert(TK.List); // This works ok...
           }).always(function() {
                 alert("Get ended: " + TK.List);
           }); 
    

    You can read it on this page http://api.jquery.com/jQuery.ajax/ but have to skip down to a paragraph that has “promise” in it.

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

Sidebar

Related Questions

I have the following jQuery code: var isUsernameAvailable = false; function CheckUsername(uname) { $.ajax({
I have the following code: for(var i = 0; i < list.length; i++){ mc_cli.get(list[i],
I have the following code: initialize: function() { _.bindAll(this); var callBack = function(res) {
Possible Duplicate: return AJAX callback return I have made a JQuery code using AJAX,
I have the following code var playingStream:NetStream; function playBytes(bytes:ByteArray): void { var connect_nc:NetConnection =
I have the following code: $(function () { var html = $('<div></div>'); html.load('preview.html', function
I have the following snippet of code: $('input#teamName').live('blur', function() { var value = $(this).val();
I have multiple instances of the following code. var start_time = new Date().getTime(); setTimeout(function
Very often, I find myself using a callback function and I don't have its
I am using the following code to follow named anchors in jquery-ui-tabs. I have

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.