-
13 Dec 2011 9:14 AM #1
AJAX Exception Handling
AJAX Exception Handling
I've tried several approaches to trap ajax successes and failures, but I can't seem to get it working. What is the correct approach to use to trap 500 errors and json data format errors? I'm not sure it matters, but I'm using Ext.define and not Ext.create and I'm using PR3.
Thanks,
Bruce
Code:Ext.define('MyModel', { extend: 'Ext.data.Model', fields: [ {name: "field", type: "string"}, ], proxy: { type: 'ajax', url: "users.json", reader: 'json', listeners: { exception: { success: function() { console.log("MyModel success."); }, failure: function() { console.log("MyModel failure."); } }, success: function(response) { console.log("MyModel: success", response); }, failure: function(response) { console.log("MyModel: failure", response); } }, exception: function(resp, oper, opts) { console.log("MyModel: exception", resp, oper, opts); }, success: function(response) { console.log("MyModel: success", response); }, failure: function(response) { console.log("MyModel: failure", response); } }
-
13 Dec 2011 9:30 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
How are you loading the data? From a Store or from Model.load?
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.
-
13 Dec 2011 10:24 AM #3
I'm loading the data from the store using autoLoad: true.
-
13 Dec 2011 10:32 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
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.
-
13 Dec 2011 11:34 AM #5
Still no luck
Still no luck
I tried the following and it still doesn't work. If the code is correct below, then I'll try to come up with a working example that shows the problem.
Thanks,
Bruce
Code:Ext.define('MyData', { extend: 'Ext.data.Store', model: 'MyModel', autoLoad: true, exception: function(resp, oper, opts) { console.log("MyModel: exception", resp, oper, opts); }, }
-
13 Dec 2011 11:38 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
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.
-
13 Dec 2011 12:51 PM #7
I'm very excited about Sencha Touch 2.0. The MVC approach is much cleaner and easy to understand and I am able to implement application features twice as fast as with 1.x. I hope the ajax exception handling will also be improved by the time 2.0 releases.
I'm not sure if the Ext.data.StoreManager listeners configuration option is an artifact or an unimplemented feature, but it would be nice if it worked.
In the meantime, I can see from your code how to set a listener on the store from within the MVC controller using the Ext.data.StoreManager.get() method if I don't use autoLoad. Otherwise, it looks like I will need to use the internal approach you described above when using the autoLoad option in the stores.
Thanks again for your help,
Bruce


Reply With Quote