4

I'm having difficulty loading JSON content from a file. console.log prints "server-side failure with status code 0", meaning that the request failed.

My JSON file URL is correct and the file is present at the given address.

Firebug shows the error:

"NetworkError: 405 Not Allowed - http://localhost:8080/4910.json?_dc=1336714070619

and the Net tag shows status 405 not allowed.

Any ideas on why this is happening?

Ext.Ajax.request({
                   url: 'http://localhost:8080/4910.json',
                   success: function(response, opts) {
                      var obj = Ext.decode(response.responseText);
                      console.log(obj[0].name);
                   },
                   failure: function(response, opts) {
                      console.log('server-side failure with status code ' + response.status);
                   }
                });

Also, what is adding the parameter _dc=1336714070619 to the end of the GET request?

4

5 回答 5

7

仅供参考..

对于谁正在添加参数 _dc。dc 代表禁用缓存
默认情况下,extjs 中的每个请求都会自动附加请求变量_dc。更多信息

如果您不想要它,只需设置disableCaching: false您的要求

Ext.Ajax.request({
    disableCaching: false,
    url: 'http://localhost:8080/4910.json',
    ......
});

对于为什么不允许
尝试打开不带 的 JSON URL 路径_dc,或者您的服务器可能有问题。

于 2012-05-11T09:58:21.797 回答
3

if the file you accessing is in the same domain, you can directly give the relative path there.

if the request is cross-domain: If you need to read data from another domain and can't set up a proxy server (some software that runs on your own domain's web server and transparently forwards requests to domainB.com, making it look like they actually came from domainA.com), you can use Ext.data.proxy.JsonP and a technique known as JSON-P (JSON with Padding), which can help you get around the problem so long as the server on domainB.com is set up to support JSON-P responses. See JsonPProxy's introduction docs for more details.

Check http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.JsonP

于 2012-05-11T07:01:04.137 回答
2

我认为您应该使用相对路径url(此处的相对路径是与 js 文件进行比较),例如,4910.json如果 json 文件与您的 js 文件位于同一文件夹中,则应该是这样。

于 2012-05-11T06:42:23.130 回答
1

也许,错误的服务器端口?

这对我很有用:

Ext.Ajax.request ({
    url: 'http://localhost:80/sof/json.json' ,
    disableCaching: false ,
    success: function (res) {
        // JSON is {name:val, type:val}
        console.log (Ext.JSON.decode(res.responseText).name);
    } ,
    failure: function () {
        console.log ('error');
    }
});
于 2012-05-11T13:58:51.880 回答
0

Check about your webserver settings. My MAMP on OSX has localhost:8888.

Every time I use a file on localhost I use relative paths.

Have you tried to change the file permissions with CHMOD? Maybe you can't even open it in your browser?

Have you tried to write to the file from within php and checked afterwards?

于 2012-05-13T20:55:51.550 回答