使用JavaScript的eBay API CORS请求返回未定义 [英] eBay API CORS request using JavaScript returns undefined

查看:66
本文介绍了使用JavaScript的eBay API CORS请求返回未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从使用JavaScript的eBay沙箱

我尝试通过CORS请求(因为它是跨域请求)来获取它,但返回的是未定义的。我尝试了许多不同的代码,但没有找到任何解决方案。
我想做的是从eBay上获取产品,并在我的Chrome扩展程序中显示它们。

I tried getting it through CORS request (as it is a cross domain request) but it returns undefined. I tried lots of different code but I haven't found any solutions. What I want to do is that fetch the products from eBay and display them in my Chrome extension.

任何帮助都是值得的。

推荐答案

我通过发出CORS请求并使用> https://github.com/Rob--W/cors-anywhere/

I found a solution by making a CORS request and using the CORS Anywhere API from https://github.com/Rob--W/cors-anywhere/

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
        });
    };
})();

来源: https://github.com/Rob--W/cors-anywhere/blob/master/demo.html

(实时示例: https://robwu.nl/cors -anywhere.html

这篇关于使用JavaScript的eBay API CORS请求返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆