jquery & ajax getting data to php in wordpress

Assuming that your script localization and other stuff are set up properly, there is an issue in your back-end script. Your data is in the following format:

data : {
    action : 'renove_vocabulary',
    id_vocabulary : vocabulary,
    id_user : user
}

But you are trying to get the data as follows:

$id_user       = $_POST['user_id'];
$id_vacabulary = $_POST['vocabulary_id'];

These 2 should be changed to match the above. So, change them into:

$id_user       = $_POST['id_user'];
$id_vacabulary = $_POST['id_vocabulary'];

Also, don’t forget to use nonces, sanitize the inputs and do some security checks. I would recommend using the REST-API altogether.

Leave a Comment