Results 1 to 3 of 3

Thread: Read HTML with Sencha Touch 1.1

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Location
    The Netherlands
    Posts
    23

    Default Answered: Read HTML with Sencha Touch 1.1

    Hi, im new to Sencha and i wanted to do a simple action: read a html file and display the different tags.

    The HTML file looks like:
    Code:
    <html><head>
    </head>
    <body bgcolor=white lang=EN-GB>
    <h1>HEADER 1 TEST</h1>
    <h2>HEADER 2 TEST</h2>
    </div>
    </body>
    </html>
    The sencha code looks like:
    Code:
    Ext.setup({
        onReady: function(){
        panel = new Ext.Panel({
            fullscreen: true
            });
    
    
        Ext.Ajax.request({
                url: 'template.htm',        
            success: function(result, request){
                panel.update(result.responseText);
                var query = Ext.query("h1");
                console.log(query);
                panel.update(query);
                },
            failure: function (result, request) { 
                console.log(result.responseText); 
                }
            });            
        }
    });
    I want to display "header 1 test", but when I run this, the output is Object HTMLHtmlElement. It works fine in the console so i wondered how I could work around the html tags.

    Thanks in advance,

    Maarten

  2. Hello,
    the query method returns an array, so you would have to construct the desired output as you would want. For this demonstration, I just took the first array element. Also, you then have to obtain the outerHTML....


    Code:
    Ext.Ajax.request({                            url: 'sample.html',
                                success: function(result, request) {
                                    panel.update(result.responseText);
                                    var query = Ext.query("h1");
                                    if(query.length > 0){
                                        console.log(query[0]);
                                        panel.update(query[0].outerHTML);
                                    }
                                },
                                failure: function (result, request) {
                                    console.log(result.responseText);
                                }
                            });

  3. #2
    Sencha Premium Member
    Join Date
    May 2008
    Location
    Pasadena, California
    Posts
    172
    Answers
    27

    Default

    Hello,
    the query method returns an array, so you would have to construct the desired output as you would want. For this demonstration, I just took the first array element. Also, you then have to obtain the outerHTML....


    Code:
    Ext.Ajax.request({                            url: 'sample.html',
                                success: function(result, request) {
                                    panel.update(result.responseText);
                                    var query = Ext.query("h1");
                                    if(query.length > 0){
                                        console.log(query[0]);
                                        panel.update(query[0].outerHTML);
                                    }
                                },
                                failure: function (result, request) {
                                    console.log(result.responseText);
                                }
                            });

  4. #3
    Sencha User
    Join Date
    Oct 2011
    Location
    The Netherlands
    Posts
    23

    Default

    This works for me.
    Thanks for the fast reply!

Posting Permissions

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