-
27 Apr 2012 8:56 PM #1
ST2 Ajax Error on Androd 2.2+
ST2 Ajax Error on Androd 2.2+
Hi,
My App running well on desktop browser without error. But when I tested on browser android 2.2+ I got an error :
I'm using simple ajax request something like this :PHP Code:Uncaught Error: You're trying to decode an invalid JSON String
FYI. - I tested my json response on jsonlint.com and valid.PHP Code:Ext.Ajax.request({
url: myurl,
success:function(response, opts){
var obj = Ext.decode(response.responseText);
console.log(response.responseText);
console.log(obj);
},
failure :function(response, opts){
}
});
- running well on my desktop browser (chrome, safari)
- I tested on my iphone iOS 5.1 running well no error
any clue what's the problem
?
thx
-
30 Apr 2012 6:59 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
What headers are in the response? Is the type valid for json?
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.
-
30 Apr 2012 7:54 AM #3
mitchellsimoens, I already replied your question about this problem here, please check it out
http://www.sencha.com/forum/showthre...-on-Androd-2.2
thanks
-
30 Apr 2012 9:37 AM #4
trinitrotoluen,
Run your app. again in Chrome and verify whether you see the error in Chrome's JavaScript console. Then, do the same in Safari and see whether you get the error logged in its console too. In my case Chrome logs the error but the app. continues running normally; and, Safari doesn't log the error and the app. runs normally too. It's only when ran under an Android 2.2 or 2.3 device that the error is logged and the app. execution is halted. You can see the logs too using the Android SDK emulator + Eclipse.
I tracked this down to the CORS OPTIONS preflight call each browser makes. In my case what I found is that the REST service's response data returned for the preflight call is being concatenated to the post-preflight call's response data (i.e. the actual call that follows a successful preflight). The concatenated JSON data is then parsed by the Sencha library, which then raises the error as it should. I say "as it should" because the concatenated result of both calls is not a valid JSON structure.
I left my research here, which means I do not know if this is a Sencha Touch behavior based on different execution paths with doing preflight/post-preflight calls for each Android, iOS, Chrome, or Safari. I took the easy way out and temporarily hacked the REST service to not return a payload (just headers) on a preflight OPTIONS call. This "solved" the problem with the concatenation/parsing, but does not answer the question as to who is doing the concatenation (i.e. Sencha Touch code or the browsers) and why.
If you or Mitchell can shed any more details on this it would be greatly appreciated.
-
30 Apr 2012 10:23 AM #5
Thanks for your reply Carlo,
Here is sample json url I try to access :
https://chrome.airasia.com/testapi/countries
After a few testing, apparently my ajax request to this url also failed on iOS 4.3.5 browser.
While browsing I read this thread :
http://stackoverflow.com/questions/6...-ajax-requests
I'm suspecting the problem is related with https ajax request not supported in the browser ? any experience how to manage this problem ?
thanks
-
1 May 2012 7:36 AM #6
trinitrotoluene, no, I don't have experience with HTTPS AJAX calls. Is there a way to test the same call from your app. via plain HTTP and see whether it works? Also, the couple of issues I've had with invalid JSON string errors (all happened under Android and never under iOS) the LogCat messages (Eclipse->DDMS view) have been invaluable pinpointing the error when running the app. under the Android emulator.


Reply With Quote