-
1 Nov 2011 1:33 PM #1
Answered: How to tell Ext.data.reader.Reader to use state code 200 as successProperty?
Answered: How to tell Ext.data.reader.Reader to use state code 200 as successProperty?
Hi, I want to fetch data with JsonP from an foreign Server-API. It returns for success:
and in case of an failure, something like this:Code:{"state":200,"results":[...]}
Now Ext.data.reader.Reader expects an boolean for successProperty. How will I tell the reader, that all worked fine, if state = 200?Code:{"state":402,"message":"Please provide a valid ..."}
I think of something like this:
could someone please point me the right direction? thx SunnyCode:Ext.define('App.model.CoolModel', { extend: 'Ext.data.Model', fields: [ {name: 'id', type: 'string'}, ], proxy: { type: 'jsonp', url: 'http://xyz/search/coolapi.json', reader: { type: 'json', success: function(data) { return data.state == 200; }, root: 'results' } } });
-
Best Answer Posted by mitchellsimoens
You will have to override the proxy in the processResponse method. There is a check where result.success !== false, that's where it checks to see if the success property is true/false. So after the result variable get's filled with data from the reader, you will need to set result.success.
-
2 Nov 2011 6:50 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3161
The successProperty is expecting a boolean value... 200 is truthy in javascript but so is 500 or 402
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.
-
2 Nov 2011 6:57 AM #3
Yes, makes sense. But how do I tell the reader that response state = 200 is success?
-
2 Nov 2011 7:16 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
- Answers
- 3161
You will have to override the proxy in the processResponse method. There is a check where result.success !== false, that's where it checks to see if the success property is true/false. So after the result variable get's filled with data from the reader, you will need to set result.success.
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.
-
2 Nov 2011 7:33 AM #5


Reply With Quote