1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    42
    Vote Rating
    0
    anthoang is on a distinguished road

      0  

    Default 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:

    Code:
                    proxy: {
                        type: 'scripttag',
                        url :'mydata.txt', //<- this don't work
                        reader: {
                            type: 'json',
                            root: 'proposals'
                        }
    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.

  2. #2
    Sencha User
    Join Date
    Jun 2011
    Posts
    350
    Vote Rating
    1
    bharatn is on a distinguished road

      0  

    Default


    For local data use 'ajax' proxy type

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    42
    Vote Rating
    0
    anthoang is on a distinguished road

      0  

    Default


    Quote Originally Posted by bharatn View Post
    For local data use 'ajax' proxy type
    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'
                        }

  4. #4
    Sencha User
    Join Date
    Jul 2011
    Posts
    1
    Vote Rating
    0
    dzubi is on a distinguished road

      0  

    Default


    Hi anthoang
    I'm stuck with the same problem, have you been able to find a solution?

  5. #5
    Sencha User
    Join Date
    Jul 2010
    Location
    Switzerland
    Posts
    78
    Vote Rating
    0
    fx-mike is on a distinguished road

      0  

    Default


    The following works for me
    Code:
    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');
    		}
    	}
    });
    Surely this can be achieved using a proxy

  6. #6
    Sencha User
    Join Date
    Jun 2011
    Posts
    42
    Vote Rating
    0
    anthoang is on a distinguished road

      0  

    Default


    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!

  7. #7
    Sencha User
    Join Date
    Jul 2010
    Location
    Switzerland
    Posts
    78
    Vote Rating
    0
    fx-mike is on a distinguished road

      0  

    Default


    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"
    }]

  8. #8
    Sencha User
    Join Date
    Jun 2011
    Posts
    8
    Vote Rating
    0
    elmogallen is on a distinguished road

      0  

    Default


    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.

  9. #9
    Sencha User
    Join Date
    Mar 2012
    Posts
    21
    Vote Rating
    0
    nakul_sagar is on a distinguished road

      0  

    Default 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..

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi