0

我想通过 AJAX 请求检索我的本地 JSON 文件数据。当我在 Chrome 中启动 html 时,会产生错误:

XMLHttpRequest 无法加载。跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource。

下面是我的代码:

function getJSON(){
                $.ajax({
                    url: "C:/Users/test/Documents/Demo/KendoTest/testJS/test.json",
                    type: "GET",
                    crossDomain: true,
                    success:function(res){
                      //do something if successful
                    },
                    error:function(e, msg){
                        alert(JSON.stringify(e) + " " + msg);
                    }
                });
            }

如果我添加dataType : 'jsonp',

它返回错误函数。

4

1 回答 1

0

如果您使用的是 google chrome,请将此扩展程序添加到您的 chrome.. 并在添加“启用跨域资源共享”开关后

https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

希望能帮助到你...

于 2017-02-26T04:12:45.407 回答