The code you have shared can work in core PHP and not in WordPress. Using AJAX in WordPress plugin is explained in WordPress documentation. Please refer – https://codex.wordpress.org/AJAX_in_Plugins
I have tried this and it works well.
The code you have shared can work in core PHP and not in WordPress. Using AJAX in WordPress plugin is explained in WordPress documentation. Please refer – https://codex.wordpress.org/AJAX_in_Plugins
I have tried this and it works well.