Sencha touch 2:获取XMLHttpRequest无法加载文件:Access-Control-Allow-Origin不允许使用data.json.Origin null

时间:2012-12-17 20:01:22

标签: extjs sencha-touch sencha-touch-2

我正在尝试从本地服务器上托管的json文件加载一些数据,但是一旦应用程序加载,我就会收到错误“XMLHttpRequest cannot load http://localhost:8080/data.json?_dc=1355779280677&page=1&start=0&limit=25. Origin null is not allowed by Access-Control-Allow-Origin. "。我的列表中没有填充记录。

我的代码如下。

Ext.define('POC.view.HomePage', {
    extend: 'Ext.TabPanel',
    requires:['Ext.TitleBar','Ext.dataview.List',
    'Ext.Ajax','Ext.data.proxy.Ajax'],
    xtype:'homePage', 
    alias: 'widget.wuHomePageView',

     config: {
     fullscreen: true,
        items: [
        {
          title: 'Home',
          iconCls: 'home',

          items: [

       {
    xtype: 'list',
        title: 'Sample',
        height: '100%',
        onItemDisclosure: true,

        store: {
        autoLoad: true,
        fields: ['name'],
            proxy: {
           type: 'json',
           url: 'http://localhost:8080/data.json',
            reader: {
               type: 'ajax',
               rootProperty: 'stores'
                }
                }
                },
             itemTpl: '{name}',

                }],

                },
            {
            title: 'Contact',
            iconCls: 'user',
            html: 'Contact Screen'
                }
            ]
            },

});

我的Json文件如下。

{
    "stores": [
        {
            "name": "Science Gallery",
            "logo": "sciencegallery.jpg",
            "desc": "Get some food",
            "telephone": "016261234",
            "city": "Dublin",
            "add1": "Pearse Street",
            "post": "2",
            "country": "Ireland",
            "latitude": "53.34422",
            "longitude": "-6.25006",
            "menu": [
                {
                    "item": "SC Sandwich"
                },
                {
                    "item": "SC Toasted Sandwich"
                },
                {
                    "item": "SC Panini"
                },
                {
                    "item": "SC Ciabatta"
                },
                {
                    "item": "SC Burrito"
                }
            ]
        },
        {
            "name": "Spar",
            "logo": "spar.jpg",
            "desc": "Get some food",
            "telephone": "016261234",
            "city": "Dublin",
            "add1": "Mayor Street",
            "post": "2",
            "country": "Ireland",
            "latitude": "53.34422",
            "longitude": "-6.25006",
            "menu": [
                {
                    "item": "Spar Sandwich"
                },
                {
                    "item": "Spar Toasted Sandwich"
                },
                {
                    "item": "Spar Panini"
                },
                {
                    "item": "Spar Ciabatta"
                },
                {
                    "item": "Spar Burrito"
                }
            ]
        }
    ]
}

请帮忙。

由于

1 个答案:

答案 0 :(得分:1)

没有像json代理这样的东西!你必须使用ajax代理:

proxy: {
   type: 'ajax',
   .....
}