0

I am trying to retrieve information from my Chargify test account but I am getting two errors: 401 (which disappears after "authenticating") and then I get 404 which I do not understand since it works on my browser after authenticating.

I am not really good with web coding so I am sure that is the problem. What i am using to try and get the data from the URL is this:

 $.ajax({
        type: "GET",
        url: "https://testingtests.chargify.com/customers.json",
        dataType: "json",
        beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', make_base_auth("someusername", "somepassword"));
        },
        success: function (response) {
            alert(response.d);
        },
        failure: function (response) {
            alert(response.d);
        },
    })

    function make_base_auth(user, password) {
        var tok = user + ':' + password;
        var hash = btoa(tok);
        return 'Basic ' + hash;
    }

EDIT: I just read that the problem seems to be that one cannot do cross domain access and that I would have to use cURL but I have not found anything on how to use it.

4

1 回答 1

0

Chargify 目前不支持 CORS(没有直接跨域访问),因此如果您希望能够通过 JavaScript 访问 API(通过代理),则需要使用代理(服务器代码)。

代理将是您使用 cURL(或任何现有的 API 包装库)的地方,然后为您的客户端代码提供一个接口以使其工作。

于 2015-02-24T17:34:14.107 回答