I am creating a Wordpress plugin and using it to learn jQuery and AJAX. I have read many posts here on WPD and SE and on other sites but cannot get to grips with what I need to do (I am a real novice at this).
I currently have this as my JS
jQuery(".my_button").click(function(){
var sn = jQuery(this).val();
alert(sn);
jQuery.get(ajaxurl,{'action': 'getname'},
function (msg) { jQuery(".result_area").html(msg);});
});
This works fine and it alerts with the value from the button click, it then calls the PHP fuction fine and displays the result correctly in the div.
What I need to do is send the value of the variable sn to the php function and use that result in a custom database query. I think that I need to add something to this line of code jQuery.get(ajaxurl,{'action': 'getname'},
But after a couple of days trying various different bits of code I cannot get the variable to appear in the PHP function.
Should I use $atts in the PHP function to retrieve this or do it in some other way.