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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:47:16+00:00 2026-05-25T18:47:16+00:00

Ok, this may be a dumb question, but I can’t find a way to

  • 0

Ok, this may be a dumb question, but I can’t find a way to solve my problem. I have this function:

function getActivityObj(sysId, date) {

    var activityObj = dojo.xhrGet({
         url: 'calendar/display-subactivities',
         content: {'sysId': sysId, 'date': date},
         handleAs: 'json',
         load: function(result) {
            console.log(result); 
         },
         error: function(){
             alert("error");
         }
    });

    var ajaxResponse = activityObj.ioArgs.xhr.response;
    return ajaxResponse;
 }

The problem is that my ajaxResponse variable is always empty, but if in firebug, the xhr object the response property is not empty.
I will use the ajax response in several places in my code so what am I doing wrong or what would be a better way to call the ajax response? Thank you. (Sorry for my bad english)

  • 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-25T18:47:16+00:00Added an answer on May 25, 2026 at 6:47 pm

    I suspect the ajaxResponse variable is empty when you call it because the xhrGet() call is made asynchronously, and the result is not actually available yet when you set ajaxResponse and return it from your function.

    By the time you view it in firebug, the XHR response has completed but it just isn’t there when your code executes.

    xhrGet() returns a dojo.Deferred object. You can use that to add a callback function for when it actually completes:

    function getActivityObj(sysId, date) {
        var activityObj = dojo.xhrGet({
             url: 'calendar/display-subactivities',
             content: {'sysId': sysId, 'date': date},
             handleAs: 'json',
             load: function(result) {
                console.log(result); 
             },
             error: function(){
                 alert("error");
             }
        });
    
        var ajaxResponse;
    
        // activityObj is a Deferred
        activityObj.addCallback(function() {
          // Use your deferred response 
          ajaxResponse = activityObj.ioArgs.xrh.response;
    
          // Now inside this function, do whatever you were going to do
          // with the xhr return data that you intended to return from
          // the wrapping function.
        });
     }
    

    I am not certain if there’s a good way to wrap the xhrGet() call in a function and attempt to return the response though, since it will always be deferred if called asynchronously.

    If it is safe to block further execution until the xhrGet() call has actually returned data, you can call it synchronously. Then your code as you have it will work without a deferred callback. Instead you would typically do whatever work the returned data was intended for in the xhrGet()‘s load() function.

    var activityObj = dojo.xhrGet({
         // Call synchronously
         sync: true,
         url: 'calendar/display- subactivities',
         content: {'sysId': sysId, 'date': date},
         // etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this may be a dumb question, but I can't seem to find the answer.
This may be a dumb question, but I can't seem to find an answer
It may be a dumb question, but I can't find an answer to this
This may be a dumb question, but I couldn't find it anywhere: How can
This may be a dumb question, I have tried googling but I am probably
This may be a simple question but I can;t find the answer anywhere. Here
This may be a very dumb question but I can't seem to get it
This may seem like a dumb question but I have IDLE and I'm trying
This may be a dumb question, but I really have no idea and I'm
This may be a very dumb question, but how can I pass a parameter

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.