getjson 和服务器
getJSON 只对控制服务器的人有用吗? 还有其他方法可以从文件中获取数据吗?
我尝试了
$.getJSON("good.json", function(data){
out=out+"good.json: "+data + ","; });
good.json = {"a":"1","b":"2"} 并得到数据“null”的结果。
这些都是有效的 JSON 文件,并且在上面使用时都给出 null:
good.htm assoc.json assoc.js Stub.json Stub.js test.js test.txt
并且所有结果都为空...
以上是在交互式设置中 http://jsbin.com/dbJSON/8/edit
输出(null)是单击“输出”即可获得。
Is getJSON only useful for those who control a server?
Is there any other alternative for getting data from a file?
i tried
$.getJSON("good.json", function(data){
out=out+"good.json: "+data + ","; });
where good.json = {"a":"1","b":"2"}
and got a result of 'null' for data.
These all are valid JSON files, and all give null when used in the above:
good.htm assoc.json assoc.js stub.json stub.js test.js test.txt
and all get a null result...
The above is in an interactive setting at
http://jsbin.com/dbJSON/8/edit
the output (of null) is to be had by clicking 'output'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的示例尝试加载
问题是您位于 jsbin.com 域中,因此存在跨域问题:jsbin.com 无法向 sn.im 发出 ajax 请求。这就是为什么你得到的是 NULL 而不是你的文件。
我希望这会对您有所帮助
杰罗姆·瓦格纳
Your example tries to load
The problem is that you are on the jsbin.com domain so you have a cross-domain issue : jsbin.com cannot make an ajax request to sn.im. This is why you get a NULL instead of your file.
I Hope this will help you
Jerome Wagner
对于 getJSON 只允许服务器特定文件的问题,答案是否定的,它将允许 JSON 格式的文件,并尝试通过删除基本标签一段时间来使用您的代码,看看它是否有效
To your question that getJSON will only alow server specific files the answer is no, it will allow file with JSON format as well also try using your code by removing the base tag for a while and see if it works