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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:10:10+00:00 2026-05-16T15:10:10+00:00

I have constructed a class in js/jQuery: function JSONRequest(request_id, type){ this.request_id = request_id; JSONsvc

  • 0

I have constructed a class in js/jQuery:

function JSONRequest(request_id, type){
    this.request_id = request_id;
    JSONsvc ='json_dispatch.php';
    this.type = type;
}

JSONRequest.prototype.query = function() {
    $.getJSON(JSONsvc,
            {request_id:this.request_id, type:this.type},
            function(data) {
                return data;
            }           
    );  
}
JSONRequest.prototype.buildKeyValues = function(data) {
    $.each(data.items, function(i,item){
        //$('textarea').text(item.comment); //hack
        $.each(item, function(j,key){
            $("#"+j).val(key);
        })
    })
}

JSONRequest.prototype.buildTableRows = function(data) {
    var tbodyContainer;
    tblRows = "";
    $.each(data.items, function(i,row){ 
        tblRows += "<tr>";      
        $.each(row, function(j,item){   
            tblRows +="<td>"+item+"</td>";
        })
        tblRows += "</tr>";
    })
    return tblRows;
}

I use it like this:

var e = new JSONRequest(this.id,this.type);
e.query();
alert(e.data); //returns Undefined

How do I get the returned JSON object for use in my other class methods?

  • 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-16T15:10:10+00:00Added an answer on May 16, 2026 at 3:10 pm

    You can’t really return data from a callback like that. Another, more serious problem that you have, is that getJSON is asynchronous. So what you should do is pass a callback in your query function so that you can have access to the data like that:

    JSONRequest.prototype.query = function(callback) {
        $.getJSON(JSONsvc,
                {request_id:this.request_id, type:this.type},
                function(data) {
                    if(callback) {
                       callback(data);
                    }                    
                }           
        );  
    };
    

    Then:

    var e = new JSONRequest(this.id,this.type);
    e.query(function(data) {
       alert(data);
    });
    

    which should work.

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

Sidebar

Related Questions

I have constructed a class to mimic a C# struct: public class Favourite {
I have a class constructor like this: public JavoImageCorrectedDataHeader() { ByteBuffer buffer = ByteBuffer.allocate(this.size());
I have a constructor method similar to this: public class Foo { public Foo
I have a constructor question for C#. I have this class: public partial class
I have constructed a map and try to put subclasses of a given class
I have a base class called LabFileBase. I have constructed a List and have
I have this table where I can generate dynamic rows (which has input <type=text
I have a problem with my JQuery, Ajax, and PHP code. I have a
I have a construct like this....... <div id=right_top_block class=drop_head> <div id=right_top_block_head class=dropper block_head rounded-corner>
I have constructed a struct in a C++ class, Lets sat it is called

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.