-
19 Nov 2012 5:05 AM #1
Sencha Touch 2.1 marks Ajax JSON response as failed if server returns empty array
Sencha Touch 2.1 marks Ajax JSON response as failed if server returns empty array
In Ext.data.reader.Reader nullResultSet is defined like this:
The problem is that the Ext.data.reader.Reader#readRecords has the following code:Code:// Empty ResultSet to return when response is falsy (null|undefined|empty string) nullResultSet: new Ext.data.ResultSet({ total : 0, count : 0, records: [], success: false })
that causes nullResultSet to be returned not only in cases specified above, but also for empty arrays. Because nullResultSet has success flag set to false, it causes the whole response to be incorrectly marked as failed.Code:if (isArray && !data.length) { return me.nullResultSet; }
BTW. I can fix it myself, but currently there's no way to contribute to Sencha Touch, right? Any plans to use GitHub or something similar for hosting Sencha Touch code?
Here's how I fixed it (touch/src/data/reader/Reader.js)
Code:if (isArray && !data.length) { - return me.nullResultSet; + return new Ext.data.ResultSet({ + total : 0, + count : 0, + records: [], + success: true + }); }
-
19 Nov 2012 12:50 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,617
- Vote Rating
- 435
Thanks for the report! I have opened a bug in our bug tracker.
-
17 Dec 2012 11:59 AM #3
I've just noticed that this ticket is closed, but not fixed, and it says "Looks like we can't reproduce the issue or there's a problem in the test case provided". What does it mean exactly? Do you want me to provide some more info or a test case?
-
23 Dec 2012 11:45 AM #4
To make it easier for you guys to reproduce this issue, here's a screencast: http://www.screencast.com/users/szim...0-1fc79e11833d
The first call to Ext.getStore("Resources").load() fetches 2 records and properly displays them in the list view. The second call fetches an empty array (valid JSON) and throws exception event instead of displaying empty list. If you want I can upload code to GitHub, but it's just a single list view + model with name field and store with REST proxy and JSON reader.
Hope that helps reproducing this issue.
Cheers,
Szymon
-
2 Jan 2013 4:17 AM #5
Bump. I really do hope you'll reopen this issue after watching the screencast.
-
26 Feb 2013 4:04 AM #6
-
26 Feb 2013 6:01 AM #7
I have seen the same thing in my app. I worked around it by calling removeAll instead of setData when I get an empty array. If this is not a bug, it is annoying that they have decided to change the way empty arrays are handled. All of my web services and code were setup on the assumption that an empty array was okay.
-
27 Feb 2013 6:15 AM #8
It got fixed by returning empty ResultSet, with 0 members, BUT, status is set to false, so if you have some items in your store, and server response returns [], old entries from your store are not deleted from your store, event if they are not existing on server :-(
-
27 Feb 2013 6:23 AM #9
I fixed it by creating an `emptyResultSet` that is almost exactly the same as `nullResultSet` but has success flag set to true (a slightly more clean approach than in my first post).
But it would be nice if someone from Sencha confirmed if it's a desired behavior (and if yes, then why) or a bug.
-
27 Feb 2013 7:08 AM #10
I changed server API so it returns not only raw data but also 'success' property, that also solves the problem.
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote