P
P
Platon Fedorovich2015-11-02 19:16:50
JavaScript
Platon Fedorovich, 2015-11-02 19:16:50

What is wrong with $.ajax() request to Telegram Bots API ("SyntaxError: Unexpected token :")?

Good evening!

Help me figure it out, please, I wrote a jQuery script that, on click, should $.ajax()return JSON data from the Telegram Bots API through a request. But when I run it, it says SyntaxError: Unexpected token :.

Here is the script:

var access_token = МОЙ_ТОКЕН;
$.ajax({
  url: 'https://api.telegram.org/bot' + access_token + '/getMe',
  dataType: 'jsonp',
  success: function(response) {
    console.log(response);
  }
});

At the same time, if you simply open this URL through a browser, then you will receive the following response:

{"ok":true,"result":{"id":XXXXXXXX,"first_name":"BotName","username":"mybot_bot"}}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-11-02
@alexey-m-ukolov

dataType: 'json',
What does jsonp have to do with it ? Since the server gives json, specify it. Well, in general, there is $.getJSON().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question