Possible to add it to ajax button?
-
I want to protect my jquery button from bots without annoying the users, so i thought of adding google’s invisible recaptcha to it. However implementation isn’t as easy as i though and i can’t seem to do it. Any help appreciated. PS: I’m not a coder.
And this is what i have:
HTML:
<button class="acf-get-content-button">Show Link</button> <div class="fa" id="acf-content-wrapper" data-id="<?php echo $post_id; ?>"></div>
JS:
<script> (function($) { $('.acf-get-content-button').click(function(e) { e.preventDefault(); $('.fa').addClass('fa-cog fa-spin fa-4x'); var $contentWrapper = $('#acf-content-wrapper'); var postId = $contentWrapper.data('id'); $.ajax({ url: "/public/ajax.php", type: "POST", data: { 'post_id': postId }, }) .done(function(data) { $('.fa').removeClass('fa-cog fa-spin fa-4x'); $contentWrapper.append(data); $('.acf-get-content-button').removeClass().addClass('.acf-get-content-button') }); }); $('.acf-get-content-button').mouseup(function() { if (event.which == 1) { $(".acf-get-content-button").hide(); } }); })(jQuery); </script>
ajax.php
<?php define('WP_USE_THEMES', false); require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' ); global $post; $post_id = $_REQUEST["post_id"]; $content = get_field( 'ebook_link_pdf', $post_id ); echo ($content);
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Possible to add it to ajax button?’ is closed to new replies.