Pass JS variable to PHP function

I trying to build a Wordpress plugin.

I have a page that displays a number of buttons and on clicking one of these buttons I want a div updated with a database query result.

I have the JS and AJAX bit just about working (this is the first time that I have done any JS and AJAX). I have the php database query working fine. I am struggling though to get the JS to pass its variable to the PHP function to do the database query. I have the variable displaying fine in a JS alert but how do I pass it to the php function? (I have done a Google search but can’t find what I am looking for).

This is what I currently have in my JS script
jQuery(".my_button").click(function(){ var sn = jQuery(this).val(); alert(sn);

I have managed to fix this with some help on another site.

Sponsor our Newsletter | Privacy Policy | Terms of Service