WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this ajax call which gets the value from a hidden input field

    <input type="hidden" name="GreetingAll" id="GreetingAll" value="Hello Everyone!" />  
    <input type="submit" id="PleasePushMe" />  
    <div id="test-div1">  

jQuery(document).ready(function() {  
    var GreetingAll = jQuery("#GreetingAll").val(); 
            type: 'POST',  
            url: 'http://www.yoursitename.com/wp-admin/admin-ajax.php',  
            data: {  
                action: 'MyAjaxFunction',  
                GreetingAll: GreetingAll,  
            success: function(data, textStatus, XMLHttpRequest){  
            error: function(MLHttpRequest, textStatus, errorThrown){  

the functions fails to return or do anything

inspite of including these functions , in the function.php

function add_myjavascript(){  
    wp_enqueue_script( 'ajax-implementation.js', get_bloginfo('template_directory') . "/scripts/ajax-implementation.js", array( 'jquery' ) );  
add_action( 'init', 'add_myjavascript' );
function MyAjaxFunction(){  
    //get the data from ajax() call  
    $GreetingAll = $_POST['GreetingAll '];  
    $results = "<h2>".$GreetingAll."</h2>";  
    // Return the String  
// creating Ajax call for WordPress  
add_action( 'wp_ajax_nopriv_ MyAjaxFunction', 'MyAjaxFunction' );  
add_action( 'wp_ajax_ MyAjaxFunction', 'MyAjaxFunction' );  

Any idea why is this code not working?

share|improve this question
Could you the next time you post a question please take the time to format your code readable? Thank you! Btw: There're spaces in function calls, etc. Turn on WP_DEBUG and PHP error reporting and show us your error output. – kaiser Jul 6 '13 at 1:02

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' ); 
share|improve this answer
Thank you , it works :) – user33702 Jun 13 '13 at 11:20
No problem, don't forget to mark the question. All the best. – userabuser Jun 13 '13 at 11:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.