gpt4 book ai didi

javascript - "No ' Access-Control-Allow-Origin ' header is present on the requested resource"来自 http ://www. google.com/的响应错误

转载 作者:行者123 更新时间:2023-12-03 00:47:58 24 4
gpt4 key购买 nike

//Create an Angular Module.
var newsModule = angular.module('NewsModule', []);

//Create an Angular Controller.
newsModule.controller('newsCtrl', ['$scope', '$http', function ($scope, $http) {
//function retrives POST,UPDATE,DELETE,GET data

$http.defaults.headers.put = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'
};
$http.defaults.useXDomain = true;

$scope.throughdata = function (){

delete $http.defaults.headers.common['X-Requested-With'];
$http.get('http://www.google.com').then(function(data,error){
alert(data);
alert(error);
$scope.days=data.data;
});



}
}
]);

但是我遇到了以下错误

XMLHttpRequest cannot load http://www.google.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

最佳答案

Access-Control-Allow-Origin 在服务器响应上设置不在客户端请求上设置,以允许来自不同来源的客户端访问有权访问响应。

就您而言,http://www.google.com/不允许您的来源访问响应。因此您无法阅读它。

有关 CORS 的更多信息:https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

关于javascript - "No ' Access-Control-Allow-Origin ' header is present on the requested resource"来自 http ://www. google.com/的响应错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24097484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com