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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:29:04+00:00 2026-06-14T13:29:04+00:00

I am trying to organize my code in Dojo but I, do not understanding

  • 0

I am trying to organize my code in Dojo but I, do not understanding how things work. I want to catch the json data after a REST call but it isn’t working. The testJson property, which I’m assigning REST return to, is always NULL.

How can I do this? I’ve copied my current code below. (I want to use my code in a ClassDAO and Controller.

define([
    'dojo/_base/declare',
    'dojo/request/xhr'
], function (declare, xhr) {

    return declare(null, {


        testJson: null,

        constructor: function(){

        },

        get: function(){

            xhr('/rest/reports', {
                method: 'get',
                handleAs: 'json',
                headers: {
                    Accept: 'application/json'
                }

            }).then(function(jsonData){

                    testJson = jsonData;

                }, function(err){
                    alert(err);
                }, function(evt){
                    // Handle a progress event from the request if the
                    // browser supports XHR2
                });

        }

    });
});
  • 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-14T13:29:05+00:00Added an answer on June 14, 2026 at 1:29 pm

    It looks like you are trying to set a class property as a variable; hence,

    testJson = jsonData;
    

    ought to be:

    this.testJson = jsonData
    

    Otherwise you are actually setting the global variable testJson, instead of a property. You also need to scope your then() function to your class:

    .then(lang.hitch(this, function(jsonData){
        this.testJson = jsonData;
    }))
    

    The lang object is dojo/_base/lang and needs adding to the define()

    define([
        "dojo/_base/declare",
        "dojo/request/xhr",
        "dojo/_base/lang"
    ], function (declare, xhr, lang) {
    

    Scoping is an important concept of Javascript that has tripped us all up in the past. See the documentation for the hitch() command for more details.

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

Sidebar

Related Questions

I'm trying to jump through some hoops to organize data in a special way.
I am trying to organize my code using the revealing module pattern. I have
In an attempt to organize my code, I'm trying to split up my (lengthy)
I've been trying to get my own opinion about this issue but could not,
I'm trying to organize my code flexible. So my application makes heavy use of
I am trying to organize my code for a Spreadsheet in several script files.
I have been trying out some different ways to organize my code in my
I am adding my code to source control (SVN). I am trying to organize
I'm trying to organize the data in the file.dat, such that I could then
I'm relatively inexperienced in VBA code, but have a workbook that I am trying

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.