0

I try to call data JSON from URL, and the source need authentication bearer I create in codeigniter framework this is my reference link

and here is my code,

$.ajax({
    url: "url",
    method: "GET",
    headers: {
        'Token': Bearer +'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNTgwMTg1MjA0LCJleHAiOjE1ODAxODg4MDR9.dG13Tv62YHgdH9SD1HKPCc_JSAVgqrJb70UlR-bqy4E'
    },
    contentType: 'application/json',
    success: function(data) {

    },
    error: function (data, status, xhr) { 
        console.log(status); 
        console.log(xhr); 
    }
});

any help would be appreciated.

13
  • Bearer should be a the string "Bearer" - and usually you'd use Authorization as the header, but if the API requires Token then that's fine - though, reading the documentation you linked to, but obviously haven't read, the header should be Authorization not Token ... and as stated the Bearer is part of the header value, i.e. it's a literal string Commented Jan 28, 2020 at 4:43
  • i.e. your code would look like Authentication: 'Bearer "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNTgwMTg1MjA0LCJleHAiOjE1ODAxODg4MDR9.dG13Tv62YHgdH9SD1HKPCc_JSAVgqrJb70UlR-bqy4E"' Commented Jan 28, 2020 at 4:49
  • headers: { 'Token' : Bearer "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNTgwMTg5MjA5LCJleHAiOjE1ODAxOTI4MDl9.zSedo6KmsdKYnbIDxNBag79QQjPh_V4spFnqt4XS4ZQ"}, like this? Commented Jan 28, 2020 at 5:41
  • i'am using Token not Authentication. thats right in documentation use authentication but i test with postman just works when i'm using Token @JaromandaX Commented Jan 28, 2020 at 5:42
  • well, then the only problem is that you are trying to use a variable named Bearer instead of the string Bearer - and perhaps the token part needs to be in " - but since your actual requirements only partially resemble the code you're basing it on, then you'll need to tweak those minutiae Commented Jan 28, 2020 at 5:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.