Vue-resource and working JSONP example

I am trying to make a JSONP request using vue-resource. Can anyone provide some working examples demonstrating the correct way to define a jsonp callback, handle the call in the Vue component, etc.

thank

** EDIT: ** For other participants, a little clarification of the situation. What is the point: I have an unauthenticated user on the site, and I wanted to let him perform some actions that require authentication (create a message, for example). However, at the very end of the creation of the post, I wanted to show him the modal login window, allow him to log in using the social service providers oAuth, and upon successful login, let me approve the mail and so on. The problem was that this call from the external interface to various domains (social providers) was blocked (CORS problem), and I tried to use JSONP to overcome the obstacle. Trying to set up a JSONP call spent a lot of time, and finally I decided to go in a completely different way:

At the end of the message creation process, a cookie is created, taking care of what was the action that was interrupted by all the necessary details. After that, the login mode is displayed. The whole process of logging into the system is performed from the server side, and at the end, when the user identification is confirmed, a redirect to the start page is performed. Next, the cookie is checked and based on the data, the action that continues execution is interrupted, as the user is authenticated now.

@bryceadams thanks again for the answer!

+4
source share
1 answer

, , - , , JSONP.

. , jsonp, . , . callback, MailChimp, c.

var options = {
    jsonp: 'c'
}

this.$http.jsonp('https://website.com', options).then(function(data){
    console.log(data.json());
}, function(error) {
    // handle errors
});
+3

Source: https://habr.com/ru/post/1649967/


All Articles