D
D
Dmitry2016-03-15 22:37:05
JavaScript
Dmitry, 2016-03-15 22:37:05

How to generate the correct ajax request to the VK server?

Once again, I wrote code that, as it seems to me, has no errors (logical and syntactic). However, the function is not executed after a successful response. This means that no response has been received. How do you write these couple of elementary lines to get the expected JSON string?

$.ajax({
        type: "GET",
        url: 'https://oauth.vk.com/access_token',
        data: "client_id=******&client_secret=***********&v=5.50&grant_type=client_credentials",
        cache: false,
        success: function(data){
            alert(JSON.stringify(data));
        }
    });

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Gromadchuk, 2016-03-16
@Papa_kfc

I see here experts in the comments who did not even try to understand the situation.
And now in order. You won’t execute the request in any case, since you can’t just execute a cross-domain request in JavaScript (of course, we are talking about VKontakte now) .
What to do in such cases? Of course you could use JSONP , which of course supportsVKontakte for their API methods, but not everything is so simple. Looking at your code, I see that you are trying to use direct authorization. It is even clear to the naked eye that the keys are not from your applications, otherwise you would know that you cannot use direct authorization on the client side. This violates all safety standards. But that's not the point, you can't even use JSONP here , since this is a server method, and you need to make a request to it exclusively from the server.
So what's the conclusion? With JS, you won't be able to make a request to this page. At most, you can create a server file with a request for this URL, and then contact your file.

R
Rikcon, 2016-03-15
@Rikcon

So what does the server generally answer you?
look in the developer console or through
the fail callback

D
Dmitry Pavlov, 2016-03-16
@dmitry_pavlov

I think it's done from the server. look:
does not give data https://oauth.vk.com/access_token/
Simple client and server user authorization...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question