这是我正在使用的代码: var queryURL ="https://api.yelp.com/v3/";var apiKey =我的钥匙"$ .ajax({网址:queryURL,方法:"GET",标头:{"accept":"application/json",访问控制允许来源":"*",授权":`Bearer $ {apiKey}`}}).then(function(res){var结果= res.dataconsole.log(结果);}); 解决方案尝试使用CORSAnywhere代理,将密钥插入下面的代码片段中并进行尝试: //JavaScript文档var queryURL ="https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/";var apiKey =我的钥匙"$ .ajax({网址:queryURL,方法:"GET",标头:{"accept":"application/json","x-requested-with":"xmlhttprequest",访问控制允许来源":"*",授权":`Bearer $ {apiKey}`}}).then(function(res){var结果= res.dataconsole.log(结果);}); I'm trying to call the Yelp Fusion API using AJAX but I'm getting the following error below. Could someone help me figure out what's going on here?api.yelp.com/v3/:1 Failed to load resource: the server responded with a status of 403 ()index.html:1 Access to XMLHttpRequest at 'https://api.yelp.com/v3/' from origin 'null' 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.Here's the code I'm using:var queryURL = "https://api.yelp.com/v3/";var apiKey = "my key"$.ajax({ url: queryURL, method: "GET", headers: { "accept": "application/json", "Access-Control-Allow-Origin":"*", "Authorization": `Bearer ${apiKey}` } }).then(function(res) { var results = res.data console.log(results); }); 解决方案 Try using the CORSAnywhere proxy, plug your key in the snip below and give it a shot:// JavaScript Documentvar queryURL = "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/";var apiKey = "my key"$.ajax({ url: queryURL, method: "GET", headers: { "accept": "application/json", "x-requested-with": "xmlhttprequest", "Access-Control-Allow-Origin":"*", "Authorization": `Bearer ${apiKey}` } }).then(function(res) { var results = res.data console.log(results); }); 这篇关于如何解决Yelp API调用中的CORS错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!