If you use AJAX, it is very easy for you to pass variables to the php file. Here is a brief example.
$('#your-button').on("click", function(){ var somevar1 = "your variable1"; var somevar2 = "your variable2"; $.ajax({ type:"POST", url: "your-phpfile.php", data: "variable1=" + somevar1 + "\u0026variable2="+ somevar2, success: function(){
Then in your php file you easily access variables using
$ajax_var1 = $_POST['variable1']; $ajax_var2 = $_POST['variable2'];
source share