Answer the question
In order to leave comments, you need to log in
How to send AJAX request from ReactJS form if Wordpress back-end?
I wrote a small pop-up form in reactjs (attached to buttons by class) and compiled js from it for use in a wp template. The question arose how to send a request to the WP engine.
I used wp_mail in a regular template, but then I ran into the need for an AJAX request (I didn’t use it before). Help me to understand.
The following method is attached to the form (instead of the standard submit, onClick is made)
getFormData() {
var data = {
name: this.refs.name.getDOMNode().value,
mail: this.refs.mail.getDOMNode().value,
text: this.refs.text.getDOMNode().value
};
$.ajax({
action: 'send_message',
url: "<?php echo admin_url('admin-ajax.php'); ?>",
name: data.name,
email: data.mail,
message: data.text
})
},
Answer the question
In order to leave comments, you need to log in
You don't have to invent anything.
1. Send data
2. On the PHP side, intercept the sending using the specified action
3. Do what you need and return a json response
4. Process the results on the success of the Ajax request
More details: https://premium.wpmudev.org/blog/using -ajax-with-w...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question