Skip to content

Instantly share code, notes, and snippets.

@barrykooij
Last active August 29, 2015 14:11
Show Gist options
  • Save barrykooij/be7bd2dd9219104a41ac to your computer and use it in GitHub Desktop.
Save barrykooij/be7bd2dd9219104a41ac to your computer and use it in GitHub Desktop.
<?php
echo '<input type="hidden" name="bk-ajax-nonce" id="bk-ajax-nonce" value="' . wp_create_nonce( 'bk-ajax-nonce' ) . '" />';
?>
<script type="text/javascript">
jQuery( document ).ready( function ( $ ) {
var data = {
action: 'my_action',
security: $( '#bk-ajax-nonce' ).val()
};
$.post( ajaxurl, data, function ( response ) {
alert( "Response: " + response );
} );
} );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment