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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:12:42+00:00 2026-06-13T22:12:42+00:00

I have a select in my html and would like to add the options

  • 0

I have a select in my html and would like to add the options via ajax when the page loads. The options values are in my DB and I get them via a call to ajax. To do so, I’m writing a class in javascript but I just can’t get my data when it runs. Please take a look :

— Main.js —

function MyLoader() {
    this._clients = null;
    this._code = null;
}

Loader.prototype = {

    var context = this;

    loadClients: function() {
        $.ajax({
            url: "my/php/",
            type: "POST",
            data: {...},
            success: function(response) {
                context._clients = response;
            }
        });
    },

    getCode: function() {...}
};

Then I have the following :

$(document).ready(function() {
    var loader = new Loader();
    loader.loadClients();
    alert(loader._clients);

    //Here I want to add my options to the select
});

My alert always returns null, and I don’t understand why. I need to save my data in the class in order to access them anytime I need to.

Can you point me to the right direction to make all my stuff work ? Thank you for your answers.

  • 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-13T22:12:43+00:00Added an answer on June 13, 2026 at 10:12 pm
    Loader.prototype = { //     v---callback parameter
        loadClients: function(callback) {
            $.ajax({
                url: "my/php/",
                context: this, // <---set success context
                type: "POST",
                data: {...},
                success: callback // <---pass callback
            });
        },
    
        getCode: function() {...}
    };
    
    $(document).ready(function() {
        var loader = new Loader();
                          //  v---pass callback
        loader.loadClients(function(response) {
            this._clients = response;
            alert(this._clients);
            //Here I want to add my options to the select
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a html select with options in my views . onchange i want
I have a select dropdownlist with 1 item selected at page load in html.
I have a number that is generated dynamically, and I would like to add
I have one Date column, formatted '17/03/2012'. I would like to be able select
I have a HTML form that has a selection drop down. I would like
I would like to create and add a calendar object plus select elements(comboboxes) for
I have a select html tag, and I want the background-color of the option
I have a html select list menu,when user select an option he/she is redirected
OK, I have two HTML select elements and a button. I need to disable
I have a classic HTML select box: Show: <select name=show id=showThreads> <option value=all selected=selected>All</option>

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.