title: Add_action hook not triggered, so Ajax returns Undefined
body: <p>It is my first time implementing ajax. I have been grappling with this sample ajax code for a couple of days, searched in stackoverflow, read blogs, tried many different solutions, even found some errors, but.. the code still return a $response = Undefined/0. </p>
  
  <p>Wordpress uploads ajax in the page, the page interacts with the server with an ajax call and returns success, but the variable $response is not passed to jquery, neither response.status nor response.message. </p>
  
  <p>In fact, $response is Undefined or 0 in the Firefox Console. </p>
  
  <p>**After all those check, I posted this question. Snake_Eyes and Froxz found some errors that I corrected. Nevertheless, ajax still returns Undefined for $response.</p>
  
  <p>I have investigate whether Wordpress calls do_stuff_pp(). 
  To do so, I have checked the do_stuff_pp() function line by line using PHP function error_log(). The analysis shows that the do_stuff_pp() function never runs. But I do not know why: :(**</p>
  
  <p>I am using jquery 1.5.1, WP 2.9.2, and php 5.2.6</p>
  
  <pre><code>function my_init() {
  
      switch ($page_num) {
      case 4445: // enrollment page1
          $path = get_bloginfo('template_directory');
          $source = $path . "/js/ajax_test.js";
          wp_enqueue_script(
                  $handle='this-is-my-ajax-handle',
                  $source,
                  $dependencies = array('jquery')
          );
          break;
      }
  
  
      switch ($page_num) {
      case 4445: // enrollment page1
          $data = array(
              'ajaxurl' =&gt; admin_url('admin-ajax.php'),
              'nonce' =&gt; wp_create_nonce('ajaxin_it'),
              'action' =&gt; 'ajaxin_it'
          );
  
          wp_localize_script('this-is-my-ajax-handle','ajaxYall', $data);     
          break;
      }
  
  }
  add_action('init', 'my_init');
  
  // Define functions for ajax:
  
  $my_action = 'ajaxin_it';
  if (defined('DOING-AJAX') &amp;&amp; DOING_AJAX) {
      // for loggedin users
      add_action('wp_ajax_' . $my_action, 'do_stuff_pp');
      // for non logged in users
      add_action('wp_ajax_nopriv_' . $my_action, 'do_stuff_pp');
  }
  
  function do_stuff_pp(){
  
      $response = array(
          'status' =&gt; 'error',
          'message' =&gt; "It's AJAX Y'all!"
      );
  
      // check is a legitimate call
      if(isset($_GET['nonce']) &amp;&amp; wp_verify_nonce($_GET['nonce'], 'ajaxin_it')){
  
          $response = array(
              'status' =&gt; 'success',
              'message' =&gt; "It's AJAX Y'all!"
          );
      }
      header('Content: application/json');    
      echo json_encode($response);
      die();
  }
  </code></pre>
  
  <p>This is the .js:</p>
  
  <pre><code>jQuery(document).ready(function($){  
  
      $('#text_ajax_yall').click(function(){
          var $el = $(this);
  
      alert(ajaxYall.nonce);
      $.ajax({url:ajaxYall.ajaxurl,action:ajaxYall.action,nonce:ajaxYall.nonce,type:'GET',dataType:'json',success:function(response, textStatus, jqXHR){
          if( 200 == jqXHR.status &amp;&amp; 'success' == textStatus ) {
              if( 'success' == response.status ){
                          $el.after( '&lt;p style="color:green;"&gt;' + response.message+ '&lt;/p&gt;' );
                      } else {
                          $el.after( '&lt;p style="color:red;"&gt;' + response.message + '&lt;/p&gt;' );
              }
          }
  //      $el.after( '&lt;p style="color:green;"&gt;' + response.message + '&lt;/p&gt;' );
          console.log(response.message, textStatus, jqXHR );      
      }});
  
      });
  
  });
  </code></pre>
  
  <p>What is the specific cause of this and how can I fix it?</p>