1. #1
    Touch Premium Member
    Join Date
    Dec 2010
    Location
    Jakarta, Indonesia
    Posts
    49
    Vote Rating
    0
    trinitrotoluen is on a distinguished road

      0  

    Default 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 :
    PHP Code:
    Uncaught ErrorYou're trying to decode an invalid JSON String 
    I'm using simple ajax request something like this :

    PHP Code:
         Ext.Ajax.request({
                     
    urlmyurl,
                        
    success:function(responseopts){
                              var 
    obj Ext.decode(response.responseText);
                                
    console.log(response.responseText);
                              
    console.log(obj);
                           },
                         
    failure :function(responseopts){
                         }
           }); 
    FYI. - I tested my json response on jsonlint.com and valid.
    - 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

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    827
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    What headers are in the response? Is the type valid for json?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Touch Premium Member
    Join Date
    Dec 2010
    Location
    Jakarta, Indonesia
    Posts
    49
    Vote Rating
    0
    trinitrotoluen is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    What headers are in the response? Is the type valid for json?
    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

  4. #4
    Sencha User
    Join Date
    Mar 2012
    Location
    Denver, CO
    Posts
    26
    Vote Rating
    1
    CarlosMS is on a distinguished road

      0  

    Default


    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.

  5. #5
    Touch Premium Member
    Join Date
    Dec 2010
    Location
    Jakarta, Indonesia
    Posts
    49
    Vote Rating
    0
    trinitrotoluen is on a distinguished road

      0  

    Default


    Quote Originally Posted by CarlosMS View Post
    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.
    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

  6. #6
    Sencha User
    Join Date
    Mar 2012
    Location
    Denver, CO
    Posts
    26
    Vote Rating
    1
    CarlosMS is on a distinguished road

      0  

    Default


    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.

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."