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

The Archive Base Latest Questions

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

I have a code like the one stated below, please how do I get

  • 0

I have a code like the one stated below, please how do I get the value for (getData), using a code like:

var instanceArray = myGraph.getInstances(component)

I was thinking myGraph.getInstances(component).getData will do it, but it failed

this.getInstances = function(component) {
    var getData = {};
        $.ajax({
            url: "/rpc/alerts2/commonObj_rpc.cfc?method=getInstances",
            data: {"component":component},
            type: "POST",
            async: true,
            success: function(data) {
                getData = $.parseJSON(data);
                console.log("hey");
                var $render_component_instance = $("#instances").empty();
                $("#instances").append($("<option />").val("all").text("All Instances (Summed)"));
                $.each(getData, function (cIndex, cItem){
                    var $instance = $("<option />").val(cItem.si_instance).text(cItem.si_label.toUpperCase());
                    $render_component_instance.append($instance);
                })
                $("#instances").multiselect("refresh");
            }
        });
};`
  • 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-15T11:37:15+00:00Added an answer on June 15, 2026 at 11:37 am

    You can’t, the get is asynchronous. getInstances returns before the GET completes, so it’s impossible for getInstances to return the data. (See further note below.)

    You have (at least) three options:

    1. Use a callback

    2. Return a blank object that will get populated later, and have the code that needs it poll it periodically

    3. Use a synchronous get (not a good idea)

    1. Use a callback

    What you can do instead is accept a callback, and then call it when the data arrives:

    this.getInstances = function(component, callback) {
    
        $.ajax({
            url: "/rpc/alerts2/commonObj_rpc.cfc?method=getInstances",
            data: {"component":component},
            type: "POST",
            async: true,
            success: function(data) {
                var getData = $.parseJSON(data);
                console.log("hey");
                var $render_component_instance = $("#instances").empty();
                $("#instances").append($("<option />").val("all").text("All Instances (Summed)"));
                $.each(getData, function (cIndex, cItem){
                    var $instance = $("<option />").val(cItem.si_instance).text(cItem.si_label.toUpperCase());
                    $render_component_instance.append($instance);
                })
                $("#instances").multiselect("refresh");
                callback(getData);
            }
        });
    };
    

    And call it like this:

    myGraph.getInstances(component, function(data) {
        // Use the data here
    });
    

    2. Return a blank object that will get populated later

    Alternately, you can return an object which will be blank to start with, but which you’ll add the data to as a property later. This may be closest to what you were looking for, from your comments below. Basically, there’s no way to access a function’s local variables from outside the function, but you can return an object and then add a property to it later.

    this.getInstances = function(component) {
    
        var obj = {};
    
        $.ajax({
            url: "/rpc/alerts2/commonObj_rpc.cfc?method=getInstances",
            data: {"component":component},
            type: "POST",
            async: false,    // <==== Note the change
            success: function(data) {
                var getData = $.parseJSON(data);
                console.log("hey");
                var $render_component_instance = $("#instances").empty();
                $("#instances").append($("<option />").val("all").text("All Instances (Summed)"));
                $.each(getData, function (cIndex, cItem){
                    var $instance = $("<option />").val(cItem.si_instance).text(cItem.si_label.toUpperCase());
                    $render_component_instance.append($instance);
                })
                $("#instances").multiselect("refresh");
    
                // Make the data available on the object
                obj.getData = getData;
            }
        });
    
        return obj; // Will be empty when we return it
    };
    

    And call it like this:

    var obj = myGraph.getInstances(component);
    
    // ...later...
    if (obj.getData) {
        // We have the data, use it
    }
    else {
        // We still don't have the data
    }
    

    3. Use a synchronous get

    I do not recommend this, but you could make the call synchronous. Note that synchronous ajax requests will go away in a future version of jQuery. But just for completeness:

    this.getInstances = function(component) {
    
        var getData;    
        $.ajax({
            url: "/rpc/alerts2/commonObj_rpc.cfc?method=getInstances",
            data: {"component":component},
            type: "POST",
            async: false,    // <==== Note the change
            success: function(data) {
                var getData = $.parseJSON(data);
                console.log("hey");
                var $render_component_instance = $("#instances").empty();
                $("#instances").append($("<option />").val("all").text("All Instances (Summed)"));
                $.each(getData, function (cIndex, cItem){
                    var $instance = $("<option />").val(cItem.si_instance).text(cItem.si_label.toUpperCase());
                    $render_component_instance.append($instance);
                })
                $("#instances").multiselect("refresh");
            }
        });
    
        return getData;
    };
    

    And call it like this:

    var getData = myGraph.getInstances(component);
    

    But again, I don’t advocate that. Synchronous ajax calls lock up the UI of the browser, leading to a bad user experience.

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

Sidebar

Related Questions

I'm training code problems like UvA and I have this one in which I
I would like to have more than one button. I tried to copy code
In following code, I have one large component, and I'd like only the level4
I have code like this in my view model: function ChatListViewModel(chats) { var self
I have code like that 010200345 i want split every first three digit please
I have code like this var MyObj = { f1 : function(o){ o.onmousedown =
I have a Nationality ComboBox like the one below and want to make it
I have code like the following... HANDLE event = CreateEvent(NULL, false, false, NULL); //
I have code like this - (IBAction)onClick:(id)sender { NSThread *thread = [[NSThread alloc]initWithTarget:parser selector:@selector(adapter:)
I have code like: @notifications = Notification.find_all_by_user_id(@user.id, :order=>'deliver_by DESC', :conditions=>deliver_by >= '#{Date.today.to_s(:db)}') logger.info @upcoming_reminders[0].inspect

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.