javascript 收到无效响应。因此不允许访问原点 'null'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24491703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Received an invalid response. Origin 'null' is therefore not allowed access
提问by chetan
I am following a book example hence the code is very simple.
This is the code:
I see an error in Chrome console:
我正在关注一本书的例子,因此代码非常简单。这是代码:
我在 Chrome 控制台中看到一个错误:
$(function() {
$(".lang").change(function(){
var element = $(this);
var id = element.attr("value");
if(id == 'english')
{
$.ajax({
type: "GET",
url: "jsfiles/english.js",
dataType: "script"
});
}
return false;
});
});
回答by Quentin
Origin null
means you are loading the HTML document directly from your file system. You can't use XMLHttpRequest without HTTP.
Originnull
意味着您直接从文件系统加载 HTML 文档。如果没有 HTTP,您就不能使用 XMLHttpRequest。
Either install a web server for your development, or dynamically generate a <script src="..."></script>
instead.
要么为您的开发安装一个 Web 服务器,要么动态生成一个<script src="..."></script>
。