i use the wordpress built-in ajax implementation in one of my plugins as follows:
jQuery('#form_data_voting').submit(function() {
jQuery.post(
ajax_object.ajax_url,
{
action : 'voting_save',
value : jQuery('#form_data_voting').serialize(),
},
function(data) {
alert(data);
}
);//get
});
And the function in PHP looks like follows:
add_action('wp_ajax_voting_save', function () {
var_dump($_POST['value']);
die();
});//wp_ajax_voting_save
I then see in the dump that all relevant fields are in one string - thanks to the serialize() function. But the problem here is, that it is stored behind the "value" variable and i can't get it out there. The string looks like this: name=testname&tel=3883838
. I can't access the name via: $_POST['name']
or $_POST['value']['name']
.
How can i access name
and tel
as POST-variables in the wordpress ajax environment or is that not possible and i have to create name and tel as values in the js-file and have to leave serialize()
out of the function?
Would be great if anybody has experiences this before and can share the solution. Thanks!