Search code examples
ajaxsencha-touch-2local-storagestorehttp-request

Sencha touch store and proxy problems


Like always I try to do this for my own, I read the documentation of sencha touch 2 for using stores but I can't make what I want, I need to make a quick application that can help me to stand how work the stores and proxy into sencha touch, and them I can add this feature to my real project. So this is what I want:

Ext.define("ejemplo.view.Main", {
    extend: 'Ext.Panel',

    requires: [
        'Ext.form.FieldSet',
    ],

    config: {
        fullscreen: true,
        scrollable: true,

        items: [
            {
                xtype: 'fieldset',
                title: 'Guardando Data',
                centered: true,

                items: [
                    {
                        xtype: 'textfield',
                        label: 'Nombre',
                    },
                    {
                        xtype: 'button',
                        ui: 'confirm',
                        text: 'Guargar',

                        handler: function(){
                            //Store my data locally
                        }                   
                    }
                ]
            },
            {
                xtype: 'button',
                text: 'Almacen',
                ui: 'action',
                docked: 'bottom',

                handler: function(){
                    //Show the data
                }
            }
        ]
    }
});

However, I know that this quick app can make the things more easily for all guys that need stand how store the data into sencha touch locally and them can use this data for whatever we need.

Is simply if I make the file and put this file into path for my app, but when I want run the app on other devices this solution no worked. So, please help

Additional, when I make and take the data how i can do a PUT Request to my server from sencha touch?


Solution

  • Ext.Ajax.request({
        url : '/your/request/to/server/url',
        method : 'GET', // You can set also method: 'PUT' (answer for 2nd question)
        params : { // your params you want to send 
            user: 'Alexis
        },
    
        success : function(response) {
        ...
        },
    
        failure : function(response) {
    
        ...
        },
    })
    

    In the callback function you could handle responce via

    if (response.responseText) {
        result = Ext.decode(response.responseText);
    }
    

    Have a look at the Sencha doc for more info

    Cheers, Oleg