Your add_actions doesn’t get hit in time, remember that WordPress ajax requests are processed by admin-ajax.php, make sure that your add_action gets called before that
Inside your JS code you used ajax.type = post, that’s wrong. I guess you wanted to use ajax.method = POST and eventually dataType = json. You can see the docs here https://api.jquery.com/jquery.ajax/
Your action doesn’t return any valid data, return some json, some string, something. Its ok to call die() but well, return something maybe ? Since you are expecting something in ajax callback
P.s. = don’t post code as image, we cannot copy easily from there
2
Answers
I can think only of 3 things:
P.s. = don’t post code as image, we cannot copy easily from there
Apart from the suggestion posted by @Diego, ajax_url should be the full URL, like
https://yourwebsite.com/wp-admin/admin-ajax.php