通过jQuery Ajax调用BigCommerce API

时间:2013-12-16 08:17:31

标签: jquery ajax api call bigcommerce

我试图通过jquery Ajax从我的BigCommerce商店中提取产品,我正在做的是通过传递用户名和令牌密钥:

var key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var auth = 'Basic ' + Base64.encode('admin:'+key);
var url = 'https://store-xxxxxxxxx.mybigcommerce.com/api/v2/products.json';

    $.ajax({
        url : url,
        method : 'GET',
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async: false,
        crossDomain: true,
        beforeSend : function(req) {
            req.setRequestHeader('Authorization', auth);
        },
        success: function(result) {
            alert('done');
            console.log(result);
        },
        error: function (request, textStatus, errorThrown) {
            console.log(request.responseText);
            console.log(textStatus);
            console.log(errorThrown);
        }
    });

但每次我得到"失败"消息。

0 个答案:

没有答案