$ .getJSON()不使用chrome

时间:2014-01-30 09:44:49

标签: javascript jquery json google-chrome getjson

此代码在FF和IE中运行良好,但在Chrome中却没有?

$(document).ready(function(){
    $.getJSON("timline.js",function(result){
     alert(result);
  });
});

铬错误: 无法加载资源:Access-Control-Allow-Origin不允许使用Origin null。文件:/// E:/jquery/parekh_timeline/timline.js

XMLHttpRequest无法加载file:/// E:/jquery/parekh_timeline/timline.js。 Access-Control-Allow-Origin不允许使用null。

2 个答案:

答案 0 :(得分:2)

这是着名的Chrome bug

运行本地Web服务器并使用localhost。我正在使用SimpleHTTPServer python模块:

python -m SimpleHTTPServer

或使用Chrome标记--allow-file-access-from-files

答案 1 :(得分:0)

您需要在Web服务器上托管您的文件。

相关问题