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?