-
30 Nov 2012 1:25 PM #1
Unanswered: Store Not Parsing JSON Data
Unanswered: Store Not Parsing JSON Data
I have a Store that gets JSON data from a WCF service. The store is calling the web service and getting data back, but my chart still displays no data, so I'm assuming it's not parsing it correctly.
**Here is my code:**
Code:// Define Model Ext.regModel('chart1model', { fields: [ {name: 'name', type: 'string'}, {name: 'data', type: 'int'} ] }); var store1 = new Ext.data.Store({ model: 'chart1model', proxy: { type: 'ajax', url: 'http://localhost:8523/WebService/GetChartData?chartType=1', reader: { type: 'json' } }, autoLoad: true });
If I take the same data and create the Store myself, the chart displays correctly:
I'm not sure what I'm doing wrong. Any help would be greatly appreciated.Code:var store1 = new Ext.data.JsonStore({ fields: ['name', 'data'], data: [ {'name':'Nov-09','data':0},{'name':'Nov-10','data':0},{'name':'Nov-11','data':0},{'name':'Nov-12','data':0},{'name':'Nov-13','data':0},{'name':'Nov-14','data':0},{'name':'Nov-15','data':0},{'name':'Nov-16','data':0},{'name':'Nov-17','data':0},{'name':'Nov-18','data':0},{'name':'Nov-19','data':0},{'name':'Nov-20','data':0},{'name':'Nov-21','data':0},{'name':'Nov-22','data':0},{'name':'Nov-23','data':0},{'name':'Nov-24','data':0},{'name':'Nov-25','data':0},{'name':'Nov-26','data':0},{'name':'Nov-27','data':0},{'name':'Nov-28','data':0},{'name':'Nov-29','data':0},{'name':'Nov-30','data':0} ] });
-
2 Dec 2012 7:59 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
Any errors? Are you on the same origin (localhost:8523)?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
3 Dec 2012 8:43 AM #3
Not on the same origin, but a work around is in place.
To confirm the data I get back I am using jQuery to consume the service, and then viewing the output in the browser. I then take that output I receive from the web service and manually create an Ext.Data.Store. This works flawlessly.
However if I try to consume the web service in the Ext.Data.Store, such as in my first example above; I can see it in debug call the web service, and the web service returns data, but no data is stored.
-
3 Dec 2012 9:09 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
Does your server support CORS? Meaning is it sending the needed headers?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
3 Dec 2012 9:25 AM #5
Yes, it's sending the headers.
I've just tried using jQuery to consume the wcf service and store the json data returned in a variable. Then assign that variable to the data field in an Ext.data.store, but I'm getting the error "Cannot read property 'length' of undefined "
-
3 Dec 2012 9:27 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
Ok, so it sounds like you don't have a config set properly. What is a sample of the data and your store config?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
3 Dec 2012 9:32 AM #7
Where retVal =Code:var store1 = new Ext.data.JsonStore ({ fields: ["name","data"], data: retVal });
[{"name":"Nov-12","data":0},{"name":"Nov-13","data":0},{"name":"Nov-14","data":0},{"name":"Nov-15","data":0},{"name":"Nov-16","data":0},{"name":"Nov-17","data":0},{"name":"Nov-18","data":0},{"name":"Nov-19","data":0},{"name":"Nov-20","data":0},{"name":"Nov-21","data":0},{"name":"Nov-22","data":0},{"name":"Nov-23","data":0},{"name":"Nov-24","data":0},{"name":"Nov-25","data":0},{"name":"Nov-26","data":0},{"name":"Nov-27","data":0},{"name":"Nov-28","data":0},{"name":"Nov-29","data":0},{"name":"Nov-30","data":0},{"name":"Dec-01","data":0},{"name":"Dec-02","data":0},{"name":"Dec-03","data":0}]
-
3 Dec 2012 10:49 AM #8Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
This works for me in ST 1.1.1:
Code:var retVal = [ {"name" : "Nov-12", "data" : 0}, {"name" : "Nov-13", "data" : 0}, {"name" : "Nov-14", "data" : 0}, {"name" : "Nov-15", "data" : 0}, {"name" : "Nov-16", "data" : 0}, {"name" : "Nov-17", "data" : 0}, {"name" : "Nov-18", "data" : 0}, {"name" : "Nov-19", "data" : 0}, {"name" : "Nov-20", "data" : 0}, {"name" : "Nov-21", "data" : 0}, {"name" : "Nov-22", "data" : 0}, {"name" : "Nov-23", "data" : 0}, {"name" : "Nov-24", "data" : 0}, {"name" : "Nov-25", "data" : 0}, {"name" : "Nov-26", "data" : 0}, {"name" : "Nov-27", "data" : 0}, {"name" : "Nov-28", "data" : 0}, {"name" : "Nov-29", "data" : 0}, {"name" : "Nov-30", "data" : 0}, {"name" : "Dec-01", "data" : 0}, {"name" : "Dec-02", "data" : 0}, {"name" : "Dec-03", "data" : 0} ]; var store1 = new Ext.data.JsonStore({ fields : ['name', 'data'], data : retVal });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
5 Dec 2012 11:36 AM #9
Alright, figured it out. It was returning a string, but Ext.data.strore was expecting an JSON array. If I parse the string to JSON it works fine.
Code:var retVal = $.parseJSON(retVal); var store1 = new Ext.data.JsonStroe({ fields : ['name','data'], data : retVal });


Reply With Quote