<分区>
我发现了很多在 ASP、PHP 等中检索产品信息的示例,但在没有任何服务器端代码的纯 JavaScript 中却找不到。
仅使用 JavaScript 有可能吗?是否有可用的包装类,甚至只是一些示例代码?
<分区>
我发现了很多在 ASP、PHP 等中检索产品信息的示例,但在没有任何服务器端代码的纯 JavaScript 中却找不到。
仅使用 JavaScript 有可能吗?是否有可用的包装类,甚至只是一些示例代码?
最佳答案
如其他答案所述,需要向 Amazon PA-API 发出 CORS 请求。
我正在开发一个 Chrome 插件,我想在其中获取并显示亚马逊产品。因此,我需要为此使用 JavaScript,但我总是会遇到跨源错误。
可能的解决方案是使用 CORS Anywhere API由 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
});
};
})();
关于javascript - 在 JavaScript 中检索亚马逊产品信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5872635/
相关文章:
amazon-web-services - S3 Glacier 对象未还原
python - 用于 Python 或 Ruby 的 Amazon Book API?
amazon-web-services - 在启动模板用户数据脚本中使用 CDK 部署时间 token 值
c# - 如何配置客户端? AWS Elasticsearch 请求 C#
javascript - 如何绑定(bind) google maps geocoder.geocode() 回调函数
javascript - 在一条路线上加载多个模板/ Controller
java - Amazon PA API 5.0 迁移 - 找不到 Maven 开发工具包依赖项(公共(public)存储库)