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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:39:59+00:00 2026-06-13T12:39:59+00:00

im getting frustrated because of this piece of code: function Model(){ this.GetAjaxData = function(){

  • 0

im getting frustrated because of this piece of code:

    function Model(){
       this.GetAjaxData = function(){ 
          //private Member to be returned
          var res;

          function setRes(newVal){
             res = newVal;
             alert(newVal); // to verify its really being called
          }

          // calls a Ajax-Service(1st param) with the given arguments(2nd param),
          // the 3rd param is a function with gets called back, commiting the 
          // output of the Ajax-Service as arguments for the called function
          tw.coach.callService(
             "GetServerTime", 
             "<inputs><variable name='input1' type='String'>lala</variable></inputs>", 
             function(arg){ setRes(arg['Result']); }
          );

          return res;
       };
    }

Now, what happens is, once an instance of model has been initialized and the method is being called like:

    var _model = new Model();
    document.getElementById("myDiv").innerHTML = _model.GetAjaxData();

the alert pops up with the expected data (the Ajax Service simply returns {Result: this came via Ajax.}) but myDiv constains undefined. This tells me that the setRes() is called correctly but it just doesn’t set the value of res.

And I have no idea why.

  • 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-13T12:40:00+00:00Added an answer on June 13, 2026 at 12:40 pm

    Change your approach taking into consideration async nature of AJAX requests:

    function Model() {
        this.GetAjaxData = function(callback) {
            var data = "<inputs><variable name='input1' type='String'>lala</variable></inputs>";
            tw.coach.callService("GetServerTime", data, function(arg) {
                callback(arg['Result']);
            });
        };
    }​
    
    var _model = new Model();
    _model.GetAjaxData(function(res) {
        document.getElementById("myDiv").innerHTML = res;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alrighty, I'm getting quite frustrated, namely because I thought I had this issue solved,
Ok getting frustrated on this one.... Using knockoutJS to do some visual interaction stuff.
I am getting frustrated with Google query's on code so I'll just ask all
So I am getting pretty frustrated with this and feel the only way to
Getting pretty frustrated with this. I installed pygtk 2.24, pycairo 1.8.10, and pyobject 2.28.3
I am getting very frustrated with this jquery form validation ajaxSubmit(); In chrome, it
Im getting frustrated because of OpenDNS and other services (ie: roadrunner) that now always
I've been frustrated in my efforts to find information about this because a lot
I'm getting frustrated because I am failing to have any control over my bar
Getting frustrated looking for answers for hours on this one... I have an .xml

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.