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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:39:56+00:00 2026-06-14T02:39:56+00:00

Here is my object and I have defined all the properties and functions but

  • 0

Here is my object and I have defined all the properties and functions but it still gives me this error result is not defined.

Here is my code

var Xml = {
    to      : null,
    from    : null,
    url     : null,
    result  : null,  //<--- I defined result here

    init: function (fromaddress, toaddress, link) {
        from    = fromaddress;
        to      = toaddress;
        url     = link;

        this.requestXml();
        return this;
    },

    requestXml: function () {
        $.ajax({
            type: "GET",
            url: url,
            dataType: "xml",
            success: this.parseXml
        });
    },

    parseXml: function (xml) {
        console.log('xml: ' + $(xml));
        result = $(xml); //<--- Assigning value to result here
    },

    getResult: function () {
        console.log('Result: ' + result); // <--- Here is says result is not defined
        return result;
    }
};

How can I solve this problem?

Update

I am calling getResult() below

var Route = {
fromurl : null,
tourl   : null,
from    : null,
to      : null,

init: function (fromaddress, toaddress) {
    from        = fromaddress;
    to          = toaddress;
    fromurl     = 'http://demo.com/url'+fromurl;
    tourl       = 'http://demo.com/url'+tourl;

    Route.searchRoute();
},

searchRoute: function () {
    var xml = Xml.init(from, to, fromurl);
    console.log(xml.getResult()); //<---- calling getResult();
}

 };
  • 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-14T02:39:57+00:00Added an answer on June 14, 2026 at 2:39 am

    The “undecorated” expression result would refer to a global variable named result, which you do not have.

    It is not correct to assume that just because a reference to result is textually inside of an object that the reference refers to a property of that object. That may be the case in other languages, but not in JavaScript.

    The solution to your problem is in one of the comments to the question. Using this. as a prefix works in these cases. Try this code:

    var x = 1;
    
    var p = {
       x: 2,
       f: function () {alert(x); alert(this.x);}
    }
    
    p.f();
    

    Here you will see 1 alerted and then 2.

    Answer to updated question

    What you have here is a classic problem. You write

    var xml = Xml.init(from, to, fromurl);
    console.log(xml.getResult()); //<---- calling getResult();
    

    The first line eventually fires of an Ajax request. Once that request is fired off, you immediately go to your second line, where you call xml.getResult(). Chances are nearly 100% that the call to getResult will happen before your Ajax call is able to fill in the value of result.

    One approach is to pass the thing you want to do with the result to the init method. In this case it looks like you want to log the result, so try

    var xml = Xml.init(from, to, fromurl, function () {console.log(xml.getResult()});
    

    Here we have a new fourth parameter to Xml.init so we have to handle that by updating the Xml object, like so (not tested):

    .
    .
    .
    init: function (fromaddress, toaddress, link, callback) {
        from    = fromaddress;
        to      = toaddress;
        url     = link;
    
        this.requestXml(callback);
        return this;
    },
    
    requestXml: function (callback) {
        $.ajax({
            type: "GET",
            url: url,
            dataType: "xml",
            success: callback
        });
    },
    
    .
    .
    .
    

    In other words, when you are going to make asynchronous calls, consume the results right away. Don’t save them away for later, because you never know when they are going to be “ready”.

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

Sidebar

Related Questions

Here is what I have currently, I'm doing this: current_account.send(object).search(params[:search]).user_id_equals_any(users).visibility_is_any(visibilities) but thats not very
I am probably over analyzing here, but with all the reading I have done
Here's a simplified example of an object I have. What I would like to
I have seen the related question here: An object with the same key already
Here is the scenario: I have an object called a Transaction that needs to
public void test(Object obj){ //Here i have to set the values of the obj
Here is my problem, I have a class which have a object who throw
Okay here is what I'm trying to do: I have a model object that
Apologies for the vague question. Here it is: I have a table object created
I have a Program Class, with properties as Id, ProgramName,ShortName and Code, im my

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.