使用代理从我的Web服务获取数据:从Sencha Touch 2休息

时间:2012-04-03 17:07:35

标签: rest sencha-touch-2

使用此代码时,我无法获得任何结果......

Ext.define('Teste.view.Main', {
extend: 'Ext.Container',
initialize: function(){    
    Ext.define('User', {
        extend: 'Ext.data.Model', 
       config: {  
            fields: ['description', 'discountCode' , 'prodCode'],
            proxy: {
                type: 'rest',
                format:'json',
                url : 'http://localhost:8080/stcws/resources/com.database.productcode/'
            }     
        }    
    });     
    var store = new Ext.create('Ext.data.Store', {     
        model: 'User'  
    }); 
    store.load();
    console.log(store.getCount());   
}});

但如果我拿出来

format:'json',

我得到了一个XML响应,我做错了什么?

2 个答案:

答案 0 :(得分:2)

要使用'Rest'代理并获取Json响应,我们只需要添加到代理:

headers: {                
    'Accept' : 'application/json'                 
},

然后拿出......

format:'json',

答案 1 :(得分:0)

使用Json Reader读取服务器响应。

http://docs.sencha.com/touch/2-0/#!/api/Ext.data.reader.Json

<强>尝试:

proxy: {
        type: 'ajax',
        url : 'users.json',
        reader: {
            type: 'json'
        }
    }

 proxy: {
            type: 'ajax',
            url : 'users.json',
            reader: {
                type: 'json'
                model: 'User'
            }
        }