I'm trying to retrieve a JSON object Via a remoteAction in Visualforce and I'm having some issues.
Controller:
global without sharing class Article_Controller {
@remoteAction
global static JSONGenerator getQuickText() {
JSONGenerator gen = JSON.createGenerator(true);
List<Articles__c> lis = [SELECT Name,Message FROM Articles__c];
gen.writeObject(lis);
return gen;
}
}
VF function
$(document).ready(function() {
try {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.Article_Controller .getQuickText}',
function(result, event) {
if (event.status) {
console.log(result);
var t = $.template('<div><img src="${Name}" />${Message}</div>');
$(selector).append( t , {
Name: jsonObj.Name,
Message: jsonObj.Message
});
}
}, {
escape: false
}
);
} catch (ex) {
alert(ex.message);
console.log(ex);
return false;
}
});
In the console I get the following error:
return gen;
toreturn gen.getAsString();
, also change the return type of the method fromJSONGenerator
toString
?