可能的解决方案是使用 CORS Anywhere API "https://github.com/Rob--W" rel="nofollow noreferrer">Rob--W
var cors_api_url = 'https://cors-anywhere.herokuapp.com/';
function doCORSRequest(options, printResult) {
var x = new XMLHttpRequest();
x.open(options.method, cors_api_url + options.url);
x.onload = x.onerror = function() {
printResult(
options.method + ' ' + options.url + '\n' +
x.status + ' ' + x.statusText + '\n\n' +
(x.responseText || '')
);
};
x.send(options.data);
}
(function() {
var outputField = document.getElementById('output');
new1();
function new1() {
// e.preventDefault();
doCORSRequest({
method: 'GET',
url: url,
}, function printResult(result) {
//result contains the response
//write your code here
});
};
})();
As stated in other answers, it is required to make a CORS request to Amazon PA-API.
I am working on a Chrome plugin where I want to fetch amazon products and display them. So, I need to use JavaScript for that but I always get cross-origin error.
I do not believe that amazon provides a jsonp version of their web services, so it is not possible directly. If you really want to do this you will have to use one of your servers as a proxy.
Here is a library that wraps the amazon product web services in a json or jsonp layer, complete with example code (if you're hosting it yourself you can just do a regular ajax call and don't need jsonp, of course).
For a more generic use case you can use thrid party apis
there are companies like INDIX that provide structured product information through api . Please click here for more details
发布评论
评论(4)
正如其他答案中所述,需要向 Amazon PA-API 发出 CORS 请求。
我正在开发一个 Chrome 插件,我想在其中获取亚马逊产品并显示它们。因此,我需要使用 JavaScript 来实现这一点,但我总是遇到跨源错误。
可能的解决方案是使用 CORS Anywhere API "https://github.com/Rob--W" rel="nofollow noreferrer">Rob--W
As stated in other answers, it is required to make a CORS request to Amazon PA-API.
I am working on a Chrome plugin where I want to fetch amazon products and display them. So, I need to use JavaScript for that but I always get cross-origin error.
The possible solution of that is using CORS Anywhere API developed by Rob--W
我不相信亚马逊提供其网络服务的 jsonp 版本,因此不可能直接提供。如果您确实想这样做,则必须使用其中一台服务器作为代理。
这里是一个将亚马逊产品Web服务包装在json或jsonp层中的库,完整使用示例代码(如果您自己托管它,您可以只进行常规 ajax 调用,当然不需要 jsonp)。
I do not believe that amazon provides a jsonp version of their web services, so it is not possible directly. If you really want to do this you will have to use one of your servers as a proxy.
Here is a library that wraps the amazon product web services in a json or jsonp layer, complete with example code (if you're hosting it yourself you can just do a regular ajax call and don't need jsonp, of course).
加布是对的。您需要通过代理传递您的请求。
请参阅:此 Web API 未启用 CORS;我该如何使用它? 有关其工作原理的示例。
Gabe is right. You'll need to pass your requests through a proxy.
See: This web API does not have CORS enabled; how can I use it? for an example of how this works.
检查此 http://docs.developer.amazonservices.com/en_US/products/ index.htm
对于更通用的用例,您可以使用第三方 api
有像 INDIX 这样的公司通过 api 提供结构化产品信息。请点击此处了解更多详细信息
https://developer.indix.com/docs#/参考/产品搜索
https://github.com/indix/indix-api-nodejs
Check this http://docs.developer.amazonservices.com/en_US/products/index.htm
For a more generic use case you can use thrid party apis
there are companies like INDIX that provide structured product information through api . Please click here for more details
https://developer.indix.com/docs#/reference/product-search
https://github.com/indix/indix-api-nodejs