【发布时间】:2019-07-22 16:36:51
【问题描述】:
我正在尝试使用 SEMrush API,我在 jQuery 中发出这样的请求:
$(document).ready(function() {
$.get(
'https://api.semrush.com',
{
type: 'phrase_this',
key: 'XXXXXXXXX',
phrase: 'lol',
database: 'uk'
},
function(data) {
console.log(data);
}
);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
这就是结果:
从源“https://example.com”访问“https://api.semrush.com/?type=phrase_this&key=XXXXXXX&phrase=lol&database=uk”处的 XMLHttpRequest 已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。
查看堆栈溢出,我发现很多人对此 API 有不同的疑问,这让我相信有某种不同的方式来发送此请求以避免被 CORS 策略阻止,或者我是愚蠢而忽略了一些东西。
我已尝试查阅文档,但没有找到任何帮助。
【问题讨论】:
-
你应该通过服务器端来做请求,而不是客户端。
标签: javascript jquery ajax api cors