![](/img/trans.png)
[英]Why the same GET request gets blocked by CORS when called within javascript but allowed from HTML src?
[英]Making ajax request in javascript when cors is not allowed from serverside?
function status(response) { if (response.status >= 200 && response.status < 300) { return Promise.resolve(response) } else { return Promise.reject(new Error(response.statusText)) } } function json(response) { return response.json() } fetch('https://apis.mapmyindia.com/advancedmaps/v1/+apikey+/autosuggest?q=delhi',{mode: 'no-cors'}) .then(status) .then(json) .then(function(data) { console.log('Request succeeded with JSON response', data); }).catch(function(error) { console.log('Request failed', error); });
上面的代码给出了错误
我也尝试过 httprequest 但它不起作用
它不起作用,因为您必须在服务器上启用 cors。 但是,您可以为此使用代理服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.