Show result JSON via Ajax

0

I'm not very knowledgeable about javascript, but I need to integrate a payment API.

I've never done integrations with any API before.

Following the documentation I saw that you first need to generate a transaction token.

So I have this code:

function GeraToken() {
    var base64 = $.encodeBASE64(AppKey:CHAVE, Signature:ASSINATURA);

$.ajax({
    url: "http://desenvolvimento.intermeio.com/api/v2_1/Token/Gerar",
    headers: { "Authorization": "Intermeio " + base64, Content-Type: application/json },
    type: "POST",
    crossDomain: true,
    dataType: "json",

    success: function () {
        alert('FOI');
    },
    error: function (xhr, status) {
        alert('NAO FOI');
    }
});
}

Where the GeraToken () function is a button that calls.

But I wanted to make sure that the call was correct. When I click the button it does not return any of the two alerts. The most ideal would be to return the same screen token, just so I can see that it worked, because I need to store that token in the database. In the API it says that the return will be in JSON.

Could anyone help me?

Thank you!

    
asked by anonymous 16.08.2017 / 20:01

1 answer

2

Hello,

From what I've analyzed and what you put into the comment, your function is probably syntax-poor. It looks like the "headers" property, the "content-type" sub-property and its value are without quotation marks, try:

function GeraToken() {
    var base64 = $.encodeBASE64(AppKey:CHAVE, Signature:ASSINATURA);

$.ajax({
    url: "http://desenvolvimento.intermeio.com/api/v2_1/Token/Gerar",
    headers: { "Authorization": "Intermeio " + base64, "Content-Type": "application/json" },
    type: "POST",
    crossDomain: true,
    dataType: "json",

    success: function () {
        alert('FOI');
    },
    error: function (xhr, status) {
        alert('NAO FOI');
    }
});
}
    
16.08.2017 / 22:54