【发布时间】:2019-03-13 05:44:34
【问题描述】:
我想使用 JavaScript 以 JSON 格式在本地存储此页面 Tableau Public Gallery feed。我一直在寻找脚本和代码 sn-ps 但我找不到任何有用的东西,因为每次运行代码时都会遇到相同的错误。
Access to XMLHttpRequest at 'https://public.tableau.com/en-us/s/gallery/feed' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
下面是我目前正在使用的代码。
$.ajax({
url:"https://public.tableau.com/en-us/s/gallery/feed",
method: 'GET',
dataType:'JSON',
headers: {
'Access-Control-Allow-Origin': '*'
},
success: function(response) {
console.log(response);
}
});
我也尝试过使用 POSTMAN。它还给出了无法得到任何响应的错误。是因为 Tableau 网站的限制,还是我做错了什么。
PS:我正在尝试在 Angular 7 项目中实现这一点。
【问题讨论】:
-
服务器需要启用 CORS 才能使上述代码正常工作。我相信他们没有这样做。
-
另外,在 Angular 7 项目中使用
$.ajax也不是一个好主意。您可能需要考虑提供可以为您拨打电话的服务 :) angular.io/tutorial/toh-pt4 这可能会对您有所帮助。
标签: javascript json angular