Results 1 to 3 of 3

Thread: Ext.util.JSON.decode() Fail to handle JSON string if obtained trough Ext.ajax.request

  1. #1
    Sencha User
    Join Date
    Jul 2009
    Posts
    61
    Vote Rating
    1
      0  

    Default Ext.util.JSON.decode() Fail to handle JSON string if obtained trough Ext.ajax.request

    Hi, I hope you can help me with this:

    I've provided a test link here for firebug investigation.

    I don't know why, but, if I ask ext.decode() to decode directly the JSON string obtained trough Ext.AJAX.request, it fails.

    If I copy/paste the string directly in ext.decode() parenthesis, it is working.

    It looks like a bug but I'm not sure it is one.

    This is the code (Some Coldfusion here too but don't botter with it) you will execute if you click the above link:

    Code:
    <CFHEADER NAME="Pragma" VALUE="no-cache">
    <CFHEADER NAME="Expires" VALUE="0"><cfscript> 
    SetEncoding("form","utf-8"); 
    SetEncoding("url","utf-8"); 
    </cfscript><cfcontent type="text/html; charset=utf-8">
    <HTML> 
    <HEAD> 
     <META http-equiv="Content-Type" content="text/html; charset=utf-8">
      <TITLE>TEST PAGE</TITLE> 
        <LINK rel="stylesheet" type="text/css" href="../js/extjs/resources/css/ext-all.css" /> 
         <SCRIPT type="text/javascript" language="JavaScript" src="../js/extjs/adapter/ext/ext-base.js"></SCRIPT> 
        <SCRIPT type="text/javascript" language="JavaScript" src="../js/extjs/ext-all.js"></SCRIPT> 
      
        <SCRIPT id="customscripts" type="text/javascript" language="JavaScript">
            function GetSomeJSONFromColdfusion(menu){
                Ext.Ajax.request({
                    url: '../json.cfc?method=getMenuInfo',
                    method: 'POST',
                    params: {
                        menu_id: menu
                    },
                    success: function(data){
                        jsondata = Ext.decode(data);
                    },
                    failure: function(){
                        alert('could not reach server');
                    }
                });
            };    
            Ext.onReady(function(){
                    GetSomeJSONFromColdfusion(1);
                    });
        </SCRIPT>
        
    </HEAD> 
    <BODY marginheight=0 marginwidth=0 rightmargin=0 bottommargin=0 leftmargin=0 >
    This page simply initiate a call to a coldfusion component, getting some JSON back. 
    But then ext.decode() trhow an error: "missing ] after element list". If, using firebug, you try to ext.decode() manually the string, you'll get successfull. Try to execute <i>Ext.decode('{"TITLE":1}');</i>.
    </body>
    </html>
    all:true

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,146
    Vote Rating
    985
      0  

    Default

    Because an Ajax request returns a response object.

    Code:
    Ext.decode(data.responseText);
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha User
    Join Date
    Jul 2009
    Posts
    61
    Vote Rating
    1
      0  

    Default

    Quote Originally Posted by evant View Post
    Because an Ajax request returns a response object.

    Code:
    Ext.decode(data.responseText);
    That was fast. Approximatly 10 time faster than the time I needed to set up the test link :-)

    Thank you very much!
    all:true

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •