使用$ .getJson从LocalDrive读取Json文件 [英] Use $.getJson To read Json File From LocalDrive
本文介绍了使用$ .getJson从LocalDrive读取Json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的C:驱动器上有一个JSON文件.如何使用$.getJson
函数从中读取内容?
I have a JSON file on my C: drive. How can I read from it using the $.getJson
function?
例如:
function getDisplay() {
var url = 'C:\Dsecure\D7-1.Json';
alert(url + "," + "Hell");
$.getJSON(url).done(function (data) {
//Do something
});
}
推荐答案
您无法向本地文件系统发出AJAX请求,因为它会被大多数浏览器的安全性阻止.您需要将D7-1.Json
文件放置在可访问的网络服务器上.
You can't make an AJAX request to the local file system as it will be blocked by most browsers security. You need to place your D7-1.Json
file on an accessible webserver.
假设您使用的是Windows,则可以在本地计算机上设置IIS,然后将请求指向localhost
进行测试.
Assuming you're using Windows, you could set up IIS on your local machine and point the request at localhost
for testing.
这篇关于使用$ .getJson从LocalDrive读取Json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文