I have added a custom link in WooCommerce Menu using this thread Add custom my account menu item based on user role in WooCommerce 3+ and Its working fine as per my expectations.
Now I have select2 library and in my new custom page http://localhost/wordpress/my-account/clients/ I have added a dropdown with having the ability to select multiple.
And below is my code through which I am detecting if the user deletes an item from the dropdown and then I am firing the below event.
jQuery('.clientchildren').on('select2:unselect', function (evt) {
var userId = evt.params.data.id;
jQuery.ajax({
type: "POST",
url: '/wp-admin/admin-ajax.php',
dataType: 'json',
delay: 250, // delay in ms while typing when to perform a AJAX search
data : {
action : 'remove_client_children_user_id',
userId : userId,
},
success: function(data)
{
var data = JSON.parse(data);
toastr["success"]("Removed Successfully." );
}
});
});
And In my functions.php file I have put the below code.
functions.php
add_action( 'wp_ajax_nopriv_remove_client_children_user_id', 'remove_client_children_user_id' );
add_action( 'wp_ajax_remove_client_children_user_id', 'remove_client_children_user_id' );
function remove_client_children_user_id() {
echo json_encode(array('status'=>1),true);
exit;
}
But it never goes inside and it keeps saying
The requested URL was not found on this server.
I even tried to use ajax calls by changing action
with some of my old existing functions like wp_ajax_get_mindesk_var_clients
by changing the action
to get_mindesk_var_clients
but still, it never goes inside to that as well.
Is it happening because I have created a new custom page and trying to achieve an ajax call to it?
Can someone guide me what should I do to make it work and where exactly it's having a problem calling ajax?
Thanks