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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:14:39+00:00 2026-06-05T14:14:39+00:00

Struggling to load json from file (myData.json) on URL into an object so I

  • 0

Struggling to load json from file (myData.json) on URL into an object so I can access property values.

— The data loads immediately, I need it a lot in the app.

— I’m going to access the data throughout the app, not just as part of one function that happens immediately after the data loads.

— I’ve ensured the data in my file is properly formatted json.

Following the example on the jquery API, shouldn’t I be able to do something simple like:

alert(jqxhr.myProperty);

and get the value? What step am I missing here? I’ve tried running eval and a variety of things like

var myObj=JSON.parse(jqxhr);

to no avail.

Please….thank you.

// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.getJSON("example.json", function() {
  alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });

// perform other work here ...

// Set another completion function for the request above
jqxhr.complete(function(){ alert("second complete"); });
  • 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-05T14:14:41+00:00Added an answer on June 5, 2026 at 2:14 pm

    I think you are making it too complicated 🙂

     var JSON;
    
     $.getJSON('example.json', function(response){
           JSON = response;
           alert(JSON.property);
     })
     //feel free to use chained handlers, or even make custom events out of them!
     .success(function() { alert("second success"); })
     .error(function() { alert("error"); })
     .complete(function() { alert("complete"); });
    

    the getJSON function automatically converts your response into a proper JSON object. No need to parse.

    You mentioned that you are using this data all over the place, so you will have to wait for the ajax call to complete before the data is accesible. That means either wrapping your entire application in the getJSON callback. Or using a custom event to determine like so:

     var JSON;
    
     $(window).on('JSONready', function(){
           alert(JSON.property);
     });
    
     $.getJSON('example.json', function(response){
           JSON = response;
           $(window).trigger('JSONready');
     });
    
     $('#elem').on('click', function(){
           //event likely to take place after ajax call has transpired
           //it would still be better to assign this listener in a callback, 
           //but you can get away with not doing it, if you put in a catch
           if(JSON){
               alert(JSON.property);
           }          
     });
    

    EDIT

    After a quick live debug, the real reason for the data being unavailable was this: javascript that consumes JSON was located in a file include the page document NORTH of inline javascript performing the call. As a result JSON was not a global variable, and scope prevented its usage. If you truly need a variable to be global so it can be used with inline JS as well as any and all included js files, you may do so like this:

      (function(){
          var limitedScopeVariable = 25;
          window.globalScopeVariable = 30;
      })();
    
      $(function(){
           alert(globalScopeVariable); //works!
           alert(limitedScopeVariable); //fails!
      });
    

    EDIT 2

    As of jQuery 3.0, callback functions are different: The
    jqXHR.success(), jqXHR.error(), and jqXHR.complete() callback methods
    are removed as of jQuery 3.0. You can use jqXHR.done(), jqXHR.fail(),
    and jqXHR.always() instead

    from the comments @mario-lurig

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

Sidebar

Related Questions

i am really struggling to load some numeric floating point data from a file
I'm struggling while trying to write generic methods to save and load data from
I'm struggling with update my item in JComboBox. When I load item from a
I am struggling to find an easy way to load my test data in
I am trying to load my Json into my class public User() { this.fbId
Im struggling with gettings the values from the correct strings.txt in my resource files
I'm still struggling to find a clean easy way to load some values in
I am struggling to pass an id successfully into my URL for the nested
this is most likely very easy but i'm struggling $(window).bind(load resize, function(){ var wH
I've been struggling with this issue for a while now. Maybe you can help.

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.