【发布时间】:2015-11-10 22:27:45
【问题描述】:
我对 jQuery 和 AJAX 很陌生,我正在尝试以下代码,只是简单的 http 获取请求。
<html>
<head>
</head>
<body>
<script src = "jquery-2.1.4.js"></script>
<script src = "app.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.get("http://google.com", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
<button>Send an HTTP GET request to a page and get the result back</button>
</body>
</html>
我收到以下错误
XMLHttpRequest 无法加载 http://google.com/。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'file://' 不允许访问。
请帮我看看我错过了什么。
【问题讨论】:
-
被称为资源访问相关的同源策略限制
-
它声明在服务器端启用 CORS,但在我的情况下它只是
http:://google.com。我该怎么做? -
在他们允许我们的网站使用之前,您不能使用谷歌数据。
标签: javascript jquery ajax http-get