1. #1
    Ext User
    Join Date
    Jan 2011
    Posts
    33
    Vote Rating
    0
    nileshbhd5 is on a distinguished road

      0  

    Default Shall i use Json or AJax here ?

    Shall i use Json or AJax here ?


    Hi,

    I am a newbie to Sencha Touch and Json, hope someone helps me out here.

    I want to read a URL, which returns the following XML

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <ns2:categories xmlns:ns2="http://www.abc.com/tar">
    <category catId="96" title="News"/>
    <category catId="97" title="Articles">
    <category catId="101" title="Destinations"/>
    <category catId="213" title="New Destinations"/>
    </ns2:categories>

    So my questions are

    1) How do i send the External url request ?
    2) How to read the Data and Display the above categories in List View

  2. #2
    Sencha Premium Member
    Join Date
    Sep 2008
    Posts
    710
    Vote Rating
    6
    Bucs is on a distinguished road

      0  

    Default


    You can send the request like so:

    Code:
            Ext.Ajax.request({
                url: 'someURL',
                params: {
                    param1: 'test'
                },
                success: function (response, opts) {
                   // Decode the response into a JSON object
                    jsonResponse = Ext.decode(response.responseText);  
                                
                }
            });
    I personally always return JSON from my apps and haven't had the need to deal with consuming XML responses yet, but you would basically need to return your XML document from the server call and the Content-Type header would have to be set to "text/xml", then you would need to configure an XML Reader to read the response into the XML Reader object. You can read the details here.

  3. #3
    Ext User
    Join Date
    Jan 2011
    Posts
    33
    Vote Rating
    0
    nileshbhd5 is on a distinguished road

      0  

    Exclamation Ext, XML

    Ext, XML


    Here are more details

    1) I have a data.xml file which looks like below ::
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <user>
    <id>1</id>
    <name>Ed Spencer</name>
    <email>ed@sencha.com</email>
    </user>
    <user>
    <id>2</id>
    <name>Abe Elias</name>
    <email>abe@sencha.com</email>
    </user>
    2) What i want to do here is read this XML data

    3 ) I used the following code For reading the Data, but its not displaying any result, can anyone help and let me know what is wrong here ?

    Code:
    Ext.regModel('User', {
    fields: ['name', 'email']
    });
    
    topicsStore = new Ext.data.Store({
    model: 'User',
    proxy: {
    type: 'ajax',
    url : 'data.xml',
    reader: {
    type: 'xml',
    model: 'User',
    record: 'user'
    
    }
    }
    
    });
    
    
    topics = new Ext.Panel({
    iconCls: 'favorites',
    title:'topics',
    cls: 'demo-list',
    items: [{
    
    xtype: 'list',
    disclosure: {
    scope: topicsStore,
    handler: function(record, btn, index) {
    alert('Disclose more info for ' + record.get('newsTitle'));
    }
    },
    store: topicsStore,
    tpl: '<tpl for="."><div class="class="contact""><table><tr><td width="70" style="font-size:20px; text-align:center; font-weight:bold">{name}</td><td><strong>{name}</strong><br>{email}</td></tr></table></div></tpl>',
    itemSelector: 'div.contact'
    //singleSelect: true
    }]
    })

  4. #4
    Sencha User
    Join Date
    Nov 2010
    Posts
    15
    Vote Rating
    0
    cybermerlin is on a distinguished road

      0  

    Default


    xml should have one root

    Code:
    <? xml .. ?>
    <users>
      <user>..</user>
      <user>..</user>
    </users>
    n mb this code for you're store:
    Code:
    topicsStore = new Ext.data.Store({
      url : 'data.xml',
      model: 'User',
      reader: new Ext.data.XmlReader({
        record: 'user',
        id: 'id',
        model: 'User'
      })
    });

  5. #5
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,360
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    you should not compare JSON with Ajax. two totally different things.

  6. #6
    Ext User
    Join Date
    Jan 2011
    Posts
    33
    Vote Rating
    0
    nileshbhd5 is on a distinguished road

      0  

    Default IT still displays Blank

    IT still displays Blank


    IT still displays Blank, doesnt read the XML file, how do i debug it ?

    Here is the XML code

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <user>
    <id>1</id>
    <name>Ed Spencer</name>
    <email>ed@sencha.com</email>
    </user>
    <user>
    <id>2</id>
    <name>Abe Elias</name>
    <email>abe@sencha.com</email>
    </user>
    Here is the topics.js File

    Code:
          
    
    Ext.regModel('User', {
    fields: ['name', 'email']
    });
    
    
    topicsStore = new Ext.data.Store({
      url : 'data.xml',
      model: 'User',
      reader: new Ext.data.XmlReader({
        record: 'user',
        id: 'id',
        model: 'User'
      })
    });
    
     topics = new Ext.Panel({
                iconCls: 'favorites',
                title:'topics',
    
                layout: Ext.is.Phone ? 'fit' : {
                    type: 'vbox',
                    align: 'center',
                    pack: 'center'
                },
                cls: 'demo-list',
                items: [{
    
                    width: Ext.is.Phone ? undefined : 300,
                    height: 500,
                    xtype: 'list',
                    disclosure: {
                        scope: topicsStore,
                        handler: function(record, btn, index) {
                           
                        }
                    },
                    store: topicsStore,
                    tpl: '<tpl for="."><div class="class="contact""><table><tr><td width="70" style="font-size:20px; text-align:center; font-weight:bold">{name}</td><td><strong>{name}</strong><br>{email}</td></tr></table></div></tpl>',
                    itemSelector: 'div.contact'
    			
                    //singleSelect: true
                }]
            })

  7. #7
    Sencha User
    Join Date
    Nov 2010
    Posts
    15
    Vote Rating
    0
    cybermerlin is on a distinguished road

      0  

    Exclamation


    Quote Originally Posted by nileshbhd5 View Post
    IT still displays Blank, doesnt read the XML file, how do i debug it ?

    Here is the XML code

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <user>
    <id>1</id>
    <name>Ed Spencer</name>
    <email>ed@sencha.com</email>
    </user>
    <user>
    <id>2</id>
    <name>Abe Elias</name>
    <email>abe@sencha.com</email>
    </user>
    i wrote you - use one root node into xml !!!! example look above

    or look example sencha sencah_example

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

      0  

    Default Hi

    Hi


    Hi , i am new to sencha touch and want to know how to use JSON parsing in sencha touch.. A simple working example will be admired ..
    Thanx in advance

Similar Threads

  1. AJAX without JSON?
    By jmuchrisf in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 10 Nov 2010, 2:52 AM
  2. AJAX + JSON
    By ueilat in forum Sencha Touch 1.x: Discussion
    Replies: 0
    Last Post: 3 Aug 2010, 12:18 AM
  3. Ajax response to json?
    By trandroid in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 6 Jul 2010, 6:36 AM
  4. Replies: 2
    Last Post: 13 Aug 2009, 8:49 AM
  5. C# and Ajax.JSON.DefaultConverter
    By nshah83 in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 25 Jan 2008, 2:26 PM

Thread Participants: 4