View Full Version : How can I add responseText directly to load() method

25 Dec 2006, 10:49 PM
How can I add an ajax response responseText directly to load() method of JSONDataModel.My responseText is a json string.

26 Dec 2006, 3:52 AM
loadData() will take an object and load it as if it was loaded through calling load(). That means you will need to eval the JSON first.

26 Dec 2006, 11:07 PM
Thanks for helping me Jack, but I have a problem with this code:

UsersXMLGrid = function(){
var dataModel = new YAHOO.ext.grid.JSONDataModel({
root: 'customers',
totalProperty: 'Total',
id: 'customer',
fields: ['id','firstname','lastname','age']});

return {
init : function() {
var data ={"customers":[

var columns= [{ header: "ID", width: 15, sortable: true },
{ header: "First Name", width: 185, sortable: true },
{ header: "Last Name", width: 145, sortable: true },
{ header: "Age", width: 30, sortable: true }];
//dataModel = new YAHOO.ext.grid.JSONDataModel(schema);
this.colModel = new YAHOO.ext.grid.DefaultColumnModel(columns);
this.grid = new YAHOO.ext.grid.Grid('example-grid',
function loadData(){
var lcallback={ success:loadSucess};
YAHOO.util.Connect.asyncRequest('GET', 'getResponse.do', lcallback);
function loadSucess(res){

YAHOO.util.Event.on(window, 'load', UsersXMLGrid.init, UsersXMLGrid, true);

This code, I'm using a request to a struts action that return a json string in res.responseText and I want to load it directly through dataModel.loadData(res.responseText). When I run this code, the grid is empty. But when I load by exist json string this.grid.dataModel.loadData(data), the grid has data. Can you show me my error and How to fix it?[/code]

26 Dec 2006, 11:14 PM
I have solve my problem. My error code is dataModel.loadData(res.responseText). When I place with dataModel.loadData(eval('('+ res.responseText+')') it work. Thanks for helping me.