-
1 Jan 2011 5:25 AM #1
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
-
1 Jan 2011 9:53 AM #2
You can send the request like so:
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.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); } });
-
3 Jan 2011 9:20 PM #3
Ext, XML
Ext, XML
Here are more details
1) I have a data.xml file which looks like below ::
2) What i want to do here is read this XML dataCode:<?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>
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 Jan 2011 5:32 AM #4
xml should have one root
n mb this code for you're store:Code:<? xml .. ?> <users> <user>..</user> <user>..</user> </users>
Code:topicsStore = new Ext.data.Store({ url : 'data.xml', model: 'User', reader: new Ext.data.XmlReader({ record: 'user', id: 'id', model: 'User' }) });
-
4 Jan 2011 12:45 PM #5Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,169
- Vote Rating
- 28
you should not compare JSON with Ajax. two totally different things.

Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
5 Jan 2011 3:47 AM #6
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
Here is the topics.js FileCode:<?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>
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 }] })
-
5 Jan 2011 10:28 AM #7
i wrote you - use one root node into xml !!!! example look above
or look example sencha sencah_example
-
7 Dec 2012 10:58 PM #8
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
-
AJAX without JSON?
By jmuchrisf in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 10 Nov 2010, 2:52 AM -
AJAX + JSON
By ueilat in forum Sencha Touch 1.x: DiscussionReplies: 0Last Post: 3 Aug 2010, 12:18 AM -
Ajax response to json?
By trandroid in forum Sencha Touch 1.x: DiscussionReplies: 1Last Post: 6 Jul 2010, 6:36 AM -
Ext.util.JSON.decode() Fail to handle JSON string if obtained trough Ext.ajax.request
By ImShogun in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 13 Aug 2009, 8:49 AM -
C# and Ajax.JSON.DefaultConverter
By nshah83 in forum Ext 2.x: Help & DiscussionReplies: 5Last Post: 25 Jan 2008, 2:26 PM


Reply With Quote