[英]getJSON doesn't work on the server but does locally
I am using jQuery for a cascading check box, but the getJSON
command dosen't work on the server (locally it works fine). 我使用jQuery进行级联复选框,但
getJSON
命令在服务器上不起作用(在本地工作正常)。 It couldn't find the data.json
file (see error debug). 它找不到
data.json
文件(请参阅错误调试)。
Part of the script: 脚本的一部分:
<script type="text/javascript" src="scripts/jquery-1.7.2.js"></script>
<script>
$(function() {
$("#json-one").change(function() {
var $dropdown = $(this);
$.getJSON("data.json?callback=?", function(data) {
var key = $dropdown.val();
var vals = [];
switch(key) {
case 'BR9':
vals = data.BR9.split(",");
break;
case 'base':
vals = ['Please choose from above'];
}
var $jsontwo = $("#json-two");
$jsontwo.empty();
$.each(vals, function(index, value) {
$jsontwo.append("<option>" + value + "</option>");
});
});
});
});
</script>
Error from firebug: 萤火虫错误:
GET http://______my url site ____/data.json 404 NOT FOUND x 25ms
If I change the line 如果我换线
$.getJSON("data.json", function(data) ...
to 至
$.getJSON("data.json?callback=?", function(data) ...
it doesn't work either. 它也不起作用。
Can anyone help me? 谁能帮我?
您是否尝试提供json文件的完整路径?
$.getJSON("http://www.mywebsite.com/folder/data.json?callback=?", function(data) {});
Is the page you are making JSON call from and the page you are making the call to are on the same domain ? 您进行JSON调用的页面和您进行调用的页面是在同一域中吗? JSON doesn't support cross domain calls and you would need to use JSONP.
JSON不支持跨域调用,因此您需要使用JSONP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.