ExtJS AJAX:XMLHttpRequest无法加载

时间:2014-07-22 13:52:51

标签: javascript ajax extjs xmlhttprequest

ExtJS新手。 下面的所有文件都存在于同一目录(下面的代码)中 - 不知道为什么我收到以下错误。即使数据存储在目录中,我是否需要使用服务器? 我在Chrome控制台上收到以下信息:

XMLHttpRequest cannot load file:///C:/Users/Jeff/Development/workspace_extjs/Chapter%2007/JSON_data/data.json?_dc=1406036611330&page=1&start=0&limit=25. 
Received an invalid response. Origin 'null' is therefore not allowed access. JSON_data.html:1
the server reported an error JSON_data.js:39

JSON_data.js:

Ext.onReady(function(){

    // Instantiate JSON store
    var departmentStore = Ext.create('Ext.data.Store', {
        fields: [
            'name',
            'active',
            'dateActive',
            'dateInactive',
            'description',
            'director',
            'numEmployees',
            {
                name: 'id',
                type: 'int'
            }
        ],
        // Configure AJAX proxy - communicates with data
        proxy: {
            type: 'ajax',
            url: 'data.json',
            // Configure JSON reader - reads and parses data
            reader: {
                type: 'json',
                root: 'data',
                idProperty: 'id',
                successProperty: 'meta.success'
            }
        }
    });

    // Print out first record or error
    departmentStore.load({
        callback: function(records, operation, successful){
            if (successful){
                console.log('department name:', records[0].get('name'));
            }
            else {
                console.log('the server reported an error');
            }
        }
    });
});

JSON_data.html:

<!doctype html>
<html>
    <head>

        <link rel="stylesheet" type="text/css" href="../../lib/extjs/resources/css/ext-all.css" />
        <script type="text/javascript" src="../../lib/extjs/ext-all-debug.js"></script>

    </head>
    <body>

        <script type="text/javascript" src='JSON_data.js'></script>

    </body>
</html>

data.json(摘录):

{
    "data" : [
        {
            "name"         : "Media Relations",
            "active"       : "",
            "dateActive"   : "04/18/2013",
            "dateInactive" : "",
            "description"  : "",
            "director"     : "",
            "numEmployees" : "7",
            "id"           : "1"
        },
        {
            "name"         : "Sales and Marketing",
            "active"       : "",
            "dateActive"   : "03/12/2012",
            "dateInactive" : "",
            "description"  : "",
            "director"     : "",
            "numEmployees" : "9",
            "id"           : "2"
        },
        {
            "name"         : "Advertising",
            "active"       : "",
            "dateActive"   : "02/15/2013",
            "dateInactive" : "",
            "description"  : "",
            "director"     : "",
            "numEmployees" : "6",
            "id"           : "100"
        }
    ],
    "meta" : {
        "success" : true,
        "msg"     : ""
    }
}

0 个答案:

没有答案