title: How to Load Ajax in Wordpress
body: <p>I'm familiar with using ajax in the ordinary way with jQuery.<br>
  I've played around it for a while, but don't understand what Wordpress needs to get it to work...<br>
  What I have here is taken from some tutorial or article.<br>
  This is in <em>functions.php</em> (in a child theme):</p>
  
  <pre><code>// code to load jquery - working fine
  
  // code to load javascript file - working fine
  
  // ENABLE AJAX :
  function add_ajax()
  {
     wp_localize_script(
      'function',
      'ajax_script',
      array( 'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ) ) );
  }
  
  $dirName = get_stylesheet_directory();  // use this to get child theme dir
  require_once ($dirName."/ajax.php");  
  
  add_action("wp_ajax_nopriv_function1", "function1"); // function in ajax.php
  
  add_action('template_redirect', 'add_ajax');  
  </code></pre>
  
  <p>The jQuery itself is loading and working fine. </p>
  
  <p>I have tried some basic ajax like the following:</p>
  
  <pre><code>jQuery(document).ready(function($){
      $('a.link').click(function(){
          $.ajax({
                url:     ajax_script.ajaxurl,
                data:    ({action  : 'function1'}),
                success: function(data){
                       $('#result').html(data);
                }
          });
          return false;
      });
  });   
  </code></pre>
  
  <p>Besides this, I don't know how I can test to see if it's even loaded correctly to begin with...</p>
  
  <p>Any help here would be appreciated.</p>
  
  <p>EDIT:<br>
  In firebug this error:  </p>
  
  <pre><code>ReferenceError: ajax_script is not defined
         url:   ajax_script.ajaxurl,
  </code></pre>