Answer the question
In order to leave comments, you need to log in
How to execute a Wordpress script from vue.js so that vue.js reacts to the result?
I'm making a plugin for wordpress, a form on a single-file component vue.js 2 (I'm not so strong in vue for an advanced level yet, I haven't deployed vuex npm and other complexities).
By design, the user on the page (generated by vue) fills out a feedback form, after which the script checks if the user is logged into wordpress - and, depending on the result, should perform actions.
The result of the Wordpress side returns in response, depending on the value of response['code'] and a choice of actions should occur.
So, the following code is called on the Submit button (in the methods section of the component):
checkWPLogin () {
let data = {
action: 'is_wp_logged',
security: ajax_php_vars.nonce,
}
$.ajax({
method: 'get',
url: ajax_php_vars.ajax_url,
action: 'is_wp_logged',
data: data,
success: function(data) {
response = data;
},
error: function(err) {
console.log(err);
}
})
},
Answer the question
In order to leave comments, you need to log in
Actually, I solved this particular problem.
Here is the corrected code that works (oddly enough :) )
async checkWPLogin () {
let data = {
action: 'is_wp_logged',
security: ajax_php_vars.nonce,
}
const { answer } = await $.ajax({
method: 'get',
url: ajax_php_vars.ajax_url,
action: 'is_wp_logged',
data: data,
success: function(data) {
response = JSON.parse(data);
},
error: function(err) {
console.log(err);
}
});
this.wp_user_status = Number( response['code'] )
if ( this.wp_user_status != 200 ) {
this.checkFBLogin()
} else {
this.fb_dialog_stage = 0
this.addReview()
}
}
import to the correct namespace, what's the problem? why do you need to call this method if it does nothing but send a request? you can make a request from your component
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question