CF7 shortcode does not work in ajax request
-
Contact Form 7’s shortcode doesn’t work in an AJAX request when called with do_shortcode
in functions.php
function get_latest() { get_sidebar(); die(); } add_action( 'wp_ajax_nopriv_get_latest', 'get_latest' ); add_action( 'wp_ajax_get_latest', 'get_latest' );my javascript:
jQuery.ajax({ type: 'POST', url: '/wp-admin/admin-ajax.php', data: { action: 'get_latest', // the PHP function to run }, success: function(data, textStatus, XMLHttpRequest) { jQuery('#latest-news').html(''); // empty an element jQuery('#latest-news').append(data); // put our list of links into it }, error: function(XMLHttpRequest, textStatus, errorThrown) { if(typeof console === "undefined") { console = { log: function() { }, debug: function() { }, }; } if (XMLHttpRequest.status == 404) { console.log('Element not found.'); } else { console.log('Error: ' + errorThrown); } } });All other shortcodes works fine.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘CF7 shortcode does not work in ajax request’ is closed to new replies.