Pass jquery variable to php function and run it

Tested this locally and found the issues. When you reg/enq the JS, you need to localize the script. This is your chance to pass anything from PHP to the script. In this case, you should, at minimum, pass the WP ajax url like this: wp_localize_script( ‘my_js_library’, ‘my_local_var’, array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ ) ) ); … Read more

How to submit form data in the same page in WordPress without reloading the page?

Your jQuery event is bound to elements with the class submit, but your submit button in the form doesn’t have that class. Either add that class to the submit button, or just target the form itself. Simply change $(“.button”).click(function() { to $(“#modalForm”).submit(function() { This will fire when the form is submitted, whether the user clicks … Read more