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

The Archive Base Latest Questions

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

I am playing with modules in Dojo 1.8 and I have a module defined

  • 0

I am playing with modules in Dojo 1.8 and I have a module defined like this:

define(["dojo/request/xhr", "dojo/json"],
  function(xhr, JSON) {

  var url = "server/provider.php";

  return {
    files: {},

    getDirList: function() {
      var self = this;
      xhr(url).then(function(response) {
        response = JSON.parse(response);
        // would love to return the JSON for use here
      }, function(err) {
        console.error(err);
      });
    }
  };

});

I have another module in which I’d love to call that method and then use it:

define(["dojo/dom",
        "dojo/dom-construct",
        "dojo/_base/array",
        "afm/utils"
        ],
function(dom,domConst,array, utils) {
  return {
    produceHtml: function() {
      var json = utils.getDirList(); //this returns undefined
      var dirLength = json.length;
      console.log(json);
      for (var i = 0; i < json.length; i++) {
        if(i % 2 === 0) {
          domConst.place('<tr class="even"><td>' + json[i].name + '</td></tr>', 'output');
        } else {
          domConst.place('<tr><td>' + json[i].name + '</td></tr>', 'output');
        }
      }

    }
  };
});

Naturally I could just put the DOM creation code INTO the util module, but that is mixing view logic where it shouldn’t be. And it’s hideous if I want to reuse the util.getDirList method.

How can I use the JSON that gets returned by that method? Is anyone else doing this?

  • 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-14T01:53:05+00:00Added an answer on June 14, 2026 at 1:53 am

    The result of the dojo/request/xhr call comes in asynchronously, so setting the response parameter is done only after returning.
    What you want is return a Promise (read up here: http://dojotoolkit.org/documentation/tutorials/1.8/promises/ ).

    But first of all: you can make the dojo/request parse the json data for you, as follows:

    require(['dojo/request'],function(request) {
        request.get('http://example.com/data.json', {handleAs:'json'}).then(...)
    })
    

    See here: http://dojotoolkit.org/reference-guide/1.8/dojo/request.html#dojo-request

    Now combining this, your getDirList function could be just:

    getDirList: function() {
        return xhr.get(url, {handleAs:'json'});
    }
    

    And then in your produceHtml you would do something like this:

    utils.getDirList.then(function(json) {
        for (var i = 0; i < json.length; i++) {
        if(i % 2 === 0) {
          domConst.place('<tr class="even"><td>' + json[i].name + '</td></tr>', 'output');
        } else {
          domConst.place('<tr><td>' + json[i].name + '</td></tr>', 'output');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this .htaccess file domain.com/modules/mymodule/.htaccess can this htaccess file handle urls like domain.com/something
I am playing with Weld-SE. I have a project which has pluggable modules. With
I'm playing with Modules and they work as advertised: the module swf's ares built
I'm playing with lagrest prime divisor and I have troubles with this code: lpd
I have been playing around with the concept of 'module' that some mvc frameworks
have been playing with Cubepoints (wordpress plugin) and have installed the ranks module but
I was playing around with Python's subprocess module, trying a few examples but I
Is there a module that I could use for playing back an audio file
I've been playing around with Python's imaplib and email module recently. I tried sending
Playing with the new(ish) url rewriting functionality for web forms, but I'm running into

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.