title: Ajax load wordpress template part
body: <p>I have 2 radio buttons in a form for payment method - I want to load a template part on click via ajax. </p>
  
  <p>Right now I can load only the credit card form - what i'm trying to do is if credit card is selected then load credit card template if paypal is selected then load paypal template part.</p>
  
  <p><strong>Form Elements</strong></p>
  
  <pre><code>&lt;input type="radio" class="radio-cc" name="method" value="creditcard"&gt;&lt;span class="radio-span"&gt;Credit Card&lt;/span&gt;
  &lt;input type="radio" class="radio-paypal" name="method" value="paypal"&gt;&lt;span class="radio-span"&gt;Paypal&lt;/span&gt;
  </code></pre>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>$("input[name=method]").change(function(){ 
      $.ajax({  
          type: 'GET',  
          url: '&lt;?php echo admin_url('admin-ajax.php');?&gt;',  
          data: {  
              action: 'CCAjax'     
          },  
          success: function(textStatus){  
             $( '.default-form' ).append( textStatus ); 
          },  
          error: function(MLHttpRequest, textStatus, errorThrown){  
              alert(errorThrown);  
          }  
      });  
  });  
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>function CCAjax()
      {
         get_template_part('cc');
          die();
      }
  
      // creating Ajax call for WordPress  
      add_action('wp_ajax_nopriv_CCAjax', 'CCAjax');
      add_action('wp_ajax_CCAjax', 'CCAjax');
  </code></pre>