Last active
April 17, 2020 22:09
-
-
Save lkoudal/5ca59dbd9168bd6d956a336b0ddc6c7c to your computer and use it in GitHub Desktop.
Using nonce from WordPress plugin in JavaScript file
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
| jQuery(document).ready(function($) { | |
| $.ajax({ | |
| url: ajaxurl, // WP variable, contains URL pointing to admin-ajax.php | |
| type: 'POST', | |
| data: { | |
| 'action':'get_custom_data', | |
| '_ajax_nonce':plugin_ajax_object.nonce, | |
| 'user_data':'Some input from a user' | |
| }, | |
| success: function( response ) { | |
| // Here we do what happens if all is good - update the interface with a success message!? | |
| }, | |
| error: function( response ) { | |
| // Whooops, something went wrong! | |
| // console.log(response); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment