PDA

View Full Version : Json data does not load into the grid



pkaur
14 Mar 2011, 11:19 AM
Hi,

I am trying to connect to a WCF(ADO.NET) Data Service that outputs Json Data in the following format:

{
"d" : [
{
"__metadata": {
"uri": "http://10.80.247.25/ODataCustomService.svc/Graph(1)", "type": "PL_TestBed.Coordinates"
}, "week": 1, "value": 25.618189831552186
}, {
"__metadata": {
"uri": "http://10.80.247.25/ODataCustomService.svc/Graph(2)", "type": "PL_TestBed.Coordinates"
}, "week": 2, "value": 77.338295936276339
}
]}
The code I have written to pull and dispay the data in the grid is as follows -


Ext.onReady(function () {
var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://10.80.247.25/ODataCustomService.svc/Graph?$format=json'
}),
reader: new Ext.data.JsonReader({
root: 'd',
id: 'week'
}, [
{ name: 'week', mapping: 'week' },
{ name: 'value', mapping: 'value' }
])
});
// load the store immeditately
ds.load();

var graphColumns = [
{ header: "week", width: 40, sortable: true, dataIndex: 'week' },
{ header: "value", width: 100, sortable: true, dataIndex: 'value' }
];
?
// Create a typical GridPanel with RowEditor plugin
var userGrid = new Ext.grid.GridPanel({
renderTo: 'user-grid',
iconCls: 'icon-grid',
frame: true,
title: 'Graph',
height: 300,
store: ds,
columns: graphColumns,
viewConfig: {
forceFit: true
}
});
});


The data is not being loaded into the store/grid. In Firefox its not throwing any error and in firebug I see the GET being successfully called and the data being returned as response. However, I beleive the data is not getting loaded into the data store.

I get the following error in IE -

Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)
Timestamp: Mon, 14 Mar 2011 19:17:19 UTC

Message: Expected ';'
Line: 2
Char: 5
Code: 0
URI: http://10.80.247.25/ODataCustomService.svc/Graph?$format=json&_dc=1300130235388&callback=stcCallback1001

Whats going on here? I tried using some other php site that returns json data and it works fine.

For example this works fine -http://extjs.com/forum/topics-remote.php'



Ext.onReady(function () {
var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://extjs.com/forum/topics-remote.php'
?
}),
reader: new Ext.data.JsonReader({
root: 'topics',
id: 'post_id'
}, [
{ name: 'post_id', mapping: 'post_id' },
{ name: 'topic_title', mapping: 'topic_title' }
])
});
?
ds.load({ params: { start: 0, limit: 20, forumId: 4} });
var graphColumns = [
{ header: "post_id", width: 40, sortable: true, dataIndex: 'post_id' },
{ header: "topic_title", width: 100, sortable: true, dataIndex: 'topic_title' }
];
?
?
var userGrid = new Ext.grid.GridPanel({
renderTo: 'user-grid',
iconCls: 'icon-grid',
frame: true,
title: 'Graph',
height: 300,
store: ds,
columns: graphColumns,
viewConfig: {
forceFit: true
}
});
});

Please advice as to whats wrong in the first example, its urgent.

Thanks,
PK

brittongr
14 Mar 2011, 12:16 PM
You are not returning:



"success":true,



It should be in the same level as "d"

pkaur
14 Mar 2011, 12:37 PM
Thanks But my question is
How is it working with the other service then? Even http://extjs.com/forum/topics-remote.php'

does not have success:'true'

If i do not have access to the server side code, how can I modify the client code to accomodate the additional parameter?





You are not returning:



"success":true,



It should be in the same level as "d"

pkaur
14 Mar 2011, 1:41 PM
Thanks I just found the solution to my problem.

Read this -http://stackoverflow.com/questions/4359026/extjs-store-reader-fully-qualified-json-property-names

In my service I just had to return the callback along with data and it worked fine.


You are not returning:



"success":true,



It should be in the same level as "d"

brittongr
14 Mar 2011, 2:01 PM
Great! Thanks for letting me to know...