-
11 Jul 2011 1:33 PM #1
Sencha example: retrieving data via a local text file rather than a json url proxy.
Sencha example: retrieving data via a local text file rather than a json url proxy.
Hi,
I am dissecting the Sencha examples to learn how to access data and use it in a Sencha application. Specifically, I am looking at the O'Reilly example http://dev.sencha.com/deploy/touch/examples/oreilly/
My goal is to prevent having to go to a separate url and instead use a text file (or any file) on my local machine.
In the code availabe in the sample, the O'Reilly app
Code:initComponent: function() { this.list = new Ext.List({ grouped: true, itemTpl: '<span class="name">{title}</span> <span class="secondary">{room}</span>', loadingText: false, store: new Ext.data.Store({ model: 'Proposal', sorters: 'time', proxy: { type: 'scripttag', url :'https://en.oreilly.com/web2010/public/mobile_app/all', // url :'mydata.txt', <- this don't work reader: { type: 'json', root: 'proposals' } }, listeners: { load: { fn: this.initializeData, scope: this } } });
When I plug the url https://en.oreilly.com/web2010/public/mobile_app/all into my browser, I'm able to extract this information and save it as a text file. But when I try to access text file in my proxy-url with something like this:
The Oreilly list doesn't get the data from the text file, and the Sencha app just hangs with no data to display. I'm wondering with anyone else has tried to access data without having to use an outside url proxy and just a local file. Let me know? thanks.Code:proxy: { type: 'scripttag', url :'mydata.txt', //<- this don't work reader: { type: 'json', root: 'proposals' }
-
11 Jul 2011 1:47 PM #2
-
11 Jul 2011 2:57 PM #3
Thank you. I tried what you suggested below. But that wasn't the magic trick. I'm still looking at how to debug data/proxy connections.
Code:proxy: { type: 'ajax', //<- this didn't work url :'mydata.json', //<- this don't work reader: { type: 'json', root: 'proposals' }
-
28 Jul 2011 1:34 AM #4
Hi anthoang
I'm stuck with the same problem, have you been able to find a solution?
-
28 Jul 2011 1:59 AM #5
The following works for me
Surely this can be achieved using a proxyCode:Ext.Ajax.request({ url: 'data.json', success: function(response, opts) { console.log(response.responseText); }, failure: function(response, opts) { //iOS in phonegap returns response.status=0 on success if(response.status == 0 && response.responseText != ''){ console.log(response.responseText); } else { console.error('failed to load data'); } } });
-
28 Jul 2011 11:06 AM #6
dzubi,
I've kinda given up.
fx-mike,
Can you provide a bigger snipplet of your code? where/how you are using the Ext.Ajax.request component. Thanks!
-
29 Jul 2011 1:20 AM #7
Well, all I actually do after the call is read the response into a store through a custom reader. But thats a really ugly workaround I need because I have to augment the data with info from a second data source before putting it into the store. Nothing you would normally need to do, thats why I cut down my code

I actually just tried the above code and it works fine for me (tested on safari).
Here is a complete example
Code:Ext.regModel('User', { fields: [ {name: 'name', type: 'string'} ] }); var s = new Ext.data.Store({ model: 'User', proxy: { type: 'ajax', url :'resources/users.json' }, listeners: { load: function(s, r){console.log(r)} } }); s.load();Code://users.json [{ "name": "anthoang" }, { "name": "mike" }]
-
29 Jul 2011 5:16 AM #8
Take a look at how I'm doing it over here:
http://www.sencha.com/forum/showthre...ocal-XML-files
I had to use a combination of jQuery and Sencha Touch. I'm sure that's horrible, but I just could not get it to work any other way.
-
10 Sep 2012 11:13 PM #9
can we write and read excel file and text file in sencha touch ?
can we write and read excel file and text file in sencha touch ?
Hi everyone..
can we write and read excel file and text file in sencha touch 1 or 2?
If so we can get the data from Excel file and stores into database pragmatically, which makes easy to update database through excel file instead of modifying in DB and again installing application.
Note: I am talking about mobile application which is not web app
Thanks in advance..


Reply With Quote