1. #1
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    691
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default [SOLVED] json.decode error when HTML code is in response

    [SOLVED] json.decode error when HTML code is in response


    Hi,

    i have following problem.

    the problem occurs on ajax-respones on IE6 with deactivated Active-X.


    if i get a json response (header: content:type: text/html for iframe) which contains html code i get a runtime error on ie6.
    breack point is the function in the core
    PHP Code:
    json.decode() 
    in ff my response.responseText look like
    PHP Code:
    ...{"html":"<p>Die Ergebnisliste <\/p>"}... 
    on IE6
    PHP Code:
    ...{"html":"<p>Mein Text &lt;\/p&gt;"}</p




    For IE6 with deactivated Active-X i use the xmlHttpRequest Fallback solution over a iframe (http://extjs.com/forum/showthread.php?t=45402).
    So my problem could be also a form upload problem with json respons.

    i am happy for all hints and tips

    regards

    nils

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    97
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    The only reliable method I know is to return a valid HTML page with a <textarea> tag with the JSON data as the value.

    (but you'll need to change some code to extract the value from the textarea in the iframe)

  3. #3
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    691
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default


    thank you for the hint, are there already solutions on the forum?

  4. #4
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    691
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default


    I found following solution:

    on server site

    PHP Code:
    $mytext '<p><span style="font-weight: bold;">IE6</span>let me cry!</p>';
    $mytext str_replace('"','\''$mytext);
    $mytext htmlspecialchars($mytext,ENT_QUOTES)); 
    i replace double quots with single ones and then change the html tags to the htmlentities.

    on client side:
    PHP Code:
    mynamespace.HtmlPanel Ext.extend(Ext.Panel, {    
          
    initComponent: function(){
            
    Ext.apply(this, {
                
    bodyStyle'padding: 5px'
            
    });     
           
    mynamespace.HtmlPanel.superclass.initComponent.apply(thisarguments);
    // Decode the htmlentities back to html tags
            
    this.html Ext.util.Format.htmlDecode(this.html); 
        }
    });
    Ext.reg('HtmlPanel',mynamespace.HtmlPanel); 
    here i decode the htmlentties bag to tags.

    to decode the singlequot i extend the decodeHtml function.
    PHP Code:
    Ext.apply(Ext.util.Format, {
            
    htmlDecode : function(value){
                return !
    value value String(value).replace(/&gt;/g">").replace(/&lt;/g"<").replace(/&quot;/g'"').replace(/&amp;/g"&").replace(/'/g, "'");
            }
    }); 

  5. #5
    Sencha User
    Join Date
    Nov 2012
    Posts
    1
    Vote Rating
    0
    gurkin is on a distinguished road

      0  

    Default got same problem with JSON

    got same problem with JSON


    I am trying to solve it with .htaccess
    any chane it can be done&

Thread Participants: 2