How to use wp_send_json() and output the value with ajax?
Hello Wordpress Developers.
I create my own plugins, and I'm stuck about how to call php functions inside class, into javascript ajax functions.
For example we have button with ID name clickme:
button id=clickMeClick Me/button
And then I make a class with functions, example like this:
?php
class myFunctions{
function a(){
$test = Hello World from wp_send_json();
wp_send_json($test);
}
}
?
and then I want to output the test variable, using ajax. Example like this:
import $ from jquery;
class trigger{
constructor(){
this.button = $(#clickme);
this.events();
}
events(){
this.button.on(click, this.buttonHandler.bind(this));
}
buttonHandler(){
$.ajax({
//how to call the Hello World from wp_send_json()?
success: response = {
//if success, alert the Hello World from wp_send_json;
alert();
}
});
}
}
I'm stuck, and I hope I get the help to solve it. Thank you in advance, wordpress Developers!
Topic ajax php plugin-development Wordpress javascript
Category Web