1) You should really use a separate JS file.
2) Check this guide: https://premium.wpmudev.org/blog/using-ajax-with-wordpress/
1) You should really use a separate JS file.
2) Check this guide: https://premium.wpmudev.org/blog/using-ajax-with-wordpress/