Answer the question
In order to leave comments, you need to log in
How to send variables to jQuery for AJAX (ReactJS application)?
The problem is the following - I don’t understand how to set a variable instead of a static string for ajax
getFormData() {
var data = {
name: this.refs.name.getDOMNode().value,
mail: this.refs.mail.getDOMNode().value,
text: this.refs.text.getDOMNode().value
};
return data;
},
handleSubmit(data=this.getFormData()) {
jQuery.post(
MyAjax.ajaxurl,
{
'action': 'send_message',
'name': data.name,
'email': data.mail,
'message': data.text
},
function(response){
alert('The server responded: ' + response);
}
);
},
Answer the question
In order to leave comments, you need to log in
Mistakes?
Check what this refers to. And the function call in the default parameters looks out of place)handleSubmit(data=this.getFormData()) {
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question