Ajax call does not work for this simple code

You have a space in your function name on the action call, add_action( ‘wp_ajax_nopriv_ MyAjaxFunction’, ‘MyAjaxFunction’ ); add_action( ‘wp_ajax_ MyAjaxFunction’, ‘MyAjaxFunction’ ); …should be, add_action( ‘wp_ajax_nopriv_MyAjaxFunction’, ‘MyAjaxFunction’ ); add_action( ‘wp_ajax_MyAjaxFunction’, ‘MyAjaxFunction’ );

AJAX – Returning Two JSON Objects with One PHP Function

If I get it correctly, You need to wrap them in an array and pass to Javascript. function get_ldap_attr() { header(“Content-type: application/json”); … // suppose you want to return $second_var echo json_encode(array($sup,$second_var)); die(); } Success function of JSON request will receive them as array. You can access them with integer index. jQuery(function() { jQuery(‘#empLanId’).on(‘blur’, function() … Read more

Getting a variable using $post ajax back from php to js response in WP

You need to send the var through your ajax request: $.post( //be suer that this var is pointing to wp-admin/admin-ajax.php WPaAjax.ajaxurl, { action : ‘my_php_action_to_do’, //here your var and its value my_var : ‘the_value’ }, function( response ) { response = jQuery.parseJSON(response); alert(response.message); } ); In your my_php_action_to_do function: function my_php_action_to_do(){ $var[‘message’] = $_POST[‘my_var’]; //Send … Read more

jquery & ajax sending data to php

First of all, your js is wrong, you are mixing the syntax of jQuery.post() and of jQuery.ajax() You should use jQuery.ajax({ type: “POST”, url: ajaxurl, data: { action: “lu_ajax”, status: “enabled” }, success: function( data ) { alert(data); } }); or jQuery.post( ajaxurl, { action: “lu_ajax”, status: “enabled” }, function(data) { alert(data); } ); After … Read more

Dynamically switch template on click

My answer is something like an application of one of the @allenericr answer points + some cache. I suggest to implement this only if the 3 templates are different in the content and not only in the aspect, otherwise a CSS + JS solution should be the best choice. Create a main page template ‘multi-template-page.php’ … Read more

Ajax contact form return 0

Your javascript is missing an action parameter with the data: $.post(action, { name: $(‘#name’).val(), email: $(‘#email’).val(), phone: $(‘#phone’).val(), subject: $(‘#subject’).val(), comments: $(‘#comments’).val(), verify: $(‘#verify’).val(), action: ‘ajaxContacForm’ // <– added action here }, function(data){ document.getElementById(‘message’).innerHTML = data; $(‘#message’).slideDown(‘slow’); $(‘#contactform img.loader’).fadeOut(‘slow’,function(){$(this).remove()}); $(‘#submit’).removeAttr(‘disabled’); if(data.match(‘success’) != null) $(‘#contactform’).slideUp(‘slow’); } );