Created
August 12, 2019 13:11
-
-
Save dsebao/28b687acd935a1183b0f47ef0f1c2150 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //In ajax.php | |
| function sendPublicform(){ | |
| if($_POST['typeform'] == 'sometypeform'){ | |
| //some actions | |
| wp_send_json(array('success' => true,'message' => __('Saved','themedomain'))); | |
| } | |
| } | |
| add_action('wp_ajax_sendPublicform', 'sendPublicform'); | |
| add_action('wp_ajax_nopriv_sendPublicform', 'sendPublicform'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('#button').on('click', function(event) { | |
| $.ajax({ | |
| type: 'POST', | |
| url: jsvar.ajaxurl, | |
| dataType: 'json', | |
| data: mydata, | |
| global: true, | |
| success: function(data){ | |
| console.log(data); | |
| }, | |
| error: function(e){ | |
| console.log(e); | |
| } | |
| }); | |
| )}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //In app.php | |
| function add_scripts(){ | |
| wp_register_script('main-js', get_template_directory_uri() . "/src/js/main.js"); | |
| global $messagesajax; | |
| $paramsLogin = array( | |
| 'msg' => $messagesajax, | |
| 'ajaxurl' => admin_url('admin-ajax.php'), | |
| ); | |
| wp_localize_script('main-js','jsvar',$paramsLogin); | |
| wp_enqueue_script('main-js'); | |
| } | |
| add_action( 'wp_enqueue_scripts', 'add_scripts' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //In functions, register the script and enqueue | |
| include_once(get_stylesheet_directory() . '/app.php'); | |
| include_once(get_stylesheet_directory() . '/ajax.php'); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// I tried to test this but when i need to receive large content (chunks of html) this is not to handy