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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:28:35+00:00 2026-05-25T14:28:35+00:00

I have a function I’m calling that loads configuration files and I need to

  • 0

I have a function I’m calling that loads configuration files and I need to check if there is any data returned, if not I need to alert that the configuration file does not exist.

Here is my code.

    // Get JSON data from server
  result = false;
function loadData(id) {
    $.get("modules/device/loadConfigurationData.php", {
        id : id
    }, function(response) {       
         for (var i =0; i < response.length -1; i++)
             if (response[i]) 
             {
                 settings[response[i].setting_name] = response[i].setting_value;     
                 result = true;
             } 
             else 
             {
                result = false;
             }                       
    }, 'json');
}

And here are the functions that load the configuration files. NOTE that configuration files do dexist for CONFIG 1 and CONFIG 2, but not CONFIG 3 and CONFIG 4.

   // Load Configuration 1
function config1() {   
    loadData(1)    
    alert(result);
    if (result) 
    {
        alert('CONFIG 1 Loaded');   
        configurationLoaded = true;      
    } 
    else 
    {
        alert('CONFIG 1 does not exist.');
    }  
}
// Load Configuration 2
function config2() {
    loadData(2)    
    alert(result);
    if (result) 
    {
        alert('CONFIG 2 Loaded');   
        configurationLoaded = true;      
    } 
    else 
    {
        alert('CONFIG 2 does not exist.');
    }              
}
// Load Configuration 3
function config3() {
    loadData(3)    
    if (result)
    {
        alert('CONFIG 3 Loaded');   
        configurationLoaded = true;      
    } 
    else 
    {
        alert('CONFIG 3 does not exist.');
    }           
   result = false;
}
// Load Configuration 4
function config4() {    
    loadData(4)    
    alert(result);
    if (result) 
    {
        alert('CONFIG 4 Loaded');   
        configurationLoaded = true;      
    } 
    else 
    {
        alert('CONFIG 4 does not exist.');
    }          
}

This should load the configuration data if data exist, otherwise it should return false and display the alert, letting the user know that the configuration file doesn’t exist. For some reason the result variable is getting reset and making it not work.

Any help would be greatly appreciated.

  • 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-05-25T14:28:35+00:00Added an answer on May 25, 2026 at 2:28 pm

    This won’t work because get is run asynchronously. So basically your result variable would most likely be alerted before the result variable is set in the callback.

    loadData(2); would still be loading. 
    alert(result); this would be called before result is populated.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function getCartItems in cart.js and I want to call that function in
If I have function names stored as strings in a Hashtable. Is there a
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function that gets x(a value) and xs(a list) and removes all
I have a function where I need to do something to a string. I
I have function that have been colled in stored procedure. The function returns a
i have function, which has to accept two types of data - Observable collection
i have function that changes background color of element and src of image. in

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.