将服务器端文件传递给 angular 的 $http.get 函数

Pass server side file to angular's $http.get function

提问人:Ayesha 提问时间:12/16/2015 最后编辑:PiotrWolkowskiAyesha 更新时间:12/16/2015 访问量:217

问:

我想获取一个服务器端JSON文件,并在AJAX get方法中使用它。一旦我们有了文件,我就可以在网格中显示。这是它的函数。

在我给出 2 个和 4 个反斜杠之前,它不会识别位置,如下所示

$http({
        method:'GET',
        url: '\\\\sample.dce.com\\data\\ping.json'       

    })
    .then(function (res) {
        $scope.gridOptions.api.setRowData(res.data);
    });

但是,我收到以下错误

XMLHttpRequest 无法加载 file://sample.dce.com/data/ping.json。只有协议方案支持跨域请求:http、data、chrome、chrome-extension、https、chrome-extension-resource。

有人可以帮我展示如何使用ajax调用在前端获取服务器端文件(使用c#)

JavaScript C# AngularJS AJAX 服务器端

评论

0赞 Alexei Levenkov 12/16/2015
旁注:通常最好提供绝对 uri(即,如果您想要本地文件,最好显式指定为 scheme,可能是“http:..”)。也用于 Windows 文件路径,当您看起来正在寻找 ftp/http/https/...资源,必须使用 。file:\ /
0赞 Ayesha 12/16/2015
阿列克谢·列文科夫(Alexei Levenkov)- 这是我试图访问的Windows文件路径。那是我有\\,文件位于服务器上
0赞 Alexei Levenkov 12/16/2015
你显然不能(正如错误清楚地解释的那样)。所以你需要弄清楚你真正想要实现什么,以及你愿意为此放弃什么(你真的不能在 http: 和 file: locations 之间有 CORS)。
0赞 Ayesha 12/16/2015
@AlexeiLevenkov - 所以它必须是 http 位置。您能提出如何实现这一目标的方法吗?
0赞 Ayesha 12/16/2015
@AlexeiLevenkov - 我应该先在服务器端将文件路径转换为 URL 吗?

答: 暂无答案