How do you use do_shortcode via AJAX call?

I dont think it is possible to do this by using the contact form 7 plugin. Because the plugin uses bind(‘click’) on the submit button JS trigger, where it supposed to be live(‘click’) to work on an AJAX loaded form. As an alternative you can use a custom made contact form, or hide the contact … Read more

Use ajax request to load sidebar

I didn’t test anything, but I imagine it would be something like this: As you must include a sidebar.php, just include an empty sidebar.php, and leave the real one to the sidebar-ajax.php, for example. To call the sidebar: <?php get_template_part(‘sidebar’); ?> And it should be something like this: <div id=”sidebar”></div> In your functions.php: add_action(‘wp_enqueue_scripts’, ‘theme_enqueue_scripts’); … Read more

Something strange with ajax

add_action and add_filter always return true. And yes, in PHP, any string that is not empty or “0” is loosely equal to the boolean true. And I see nothing wrong with your die code. It’s hooked to wp_ajax_my_action, so you need to make a call to the admin-ajax.php as an authenticated user, with the my_action … Read more

need a confirmation text to appear on email submission

Simply add a Success callback to your Ajax function: $(‘#sendEmail’).click(function(){ $.ajax({ type: ‘POST’, url: ‘www.example.com/email.php’, data: { content: $(‘#email-data’).html()}, success: function(data) { //data variable can be used if your ajax call returns something do_stuff_here(); } }); }); In your case, you could do something like success: function() { $(‘body’).append(‘<div class=”success”>Success!</div>’); } However, is there a … Read more

problem using ajax url

You should use the WP AJAX APIs rather than reinventing them in your home template, e.g.: functions.php : // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php) wp_localize_script( ‘my-ajax-request’, ‘MyAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); add_action(‘wp_ajax_my_action’, ‘my_action_callback’); add_action(‘wp_ajax_nopriv_my_action’, ‘my_action_callback’); function my_action_callback() { $content=”something to send back to the … Read more

Not getting an ajax readystatechange on my page

Based on the comment by Ralf912 I tried to find out what the console and devtools in Chrome as all about. This debugger made clear what is wrong with my script, it’s not a WordPress specific problem, but in case others think it is I’ll explain. It may be that WordPress has set up an … Read more

Load page HTML content through AJAX

An AJAX request is a request from a client like any other request. Just request the URL like normal, but with Javascript. As far as that goes, this should be simple. If you’ve done item #2– “I’ll wrap the header/footer/sidebars…”– correctly there should be no problem except that page specific functions won’t run. That is … Read more