title: Wordpress Simple AJAX Get Request
body: <p>I've got a JavaScript file that's using AJAX to get a PHP file that has WordPress functions and simple HTML in. My JavaScript file is working fine with the jQuery functionality inside to grab my file, but as the file has WordPress functionality inside, it's giving WordPress errors because the WordPress functionality obviously isn't included--this is being used on the front-end.</p>
  
  <p><strong>AJAX Call</strong></p>
  
  <pre><code>$.ajax({
      url: wnm_custom.template_url + "/admin/includes/header1.php",
          success: function(html) {
          $("body").append(html);
          }
      });
  </code></pre>
  
  <p>Do I have to load the AJAX through WordPress and if so surely it would be simple as the functionality is working just the WordPress functionality is not?</p>
  
  <p>All the WordPress functions within my header1.php file are just undefined.</p>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>$.ajax({
      url: wnm_custom.template_url.ajaxurl,
          type: "POST",
          cache: false,
          data: {action: "get_top_main"},
          success: function(response) {
              alert(response);
          }
      });
  
  function get_top_main() {
      include(get_template_directory_uri() . '/admin/includes/header1.php'); 
  }
  
  add_action('wp_ajax_get_top_main', 'get_top_main_up');
  add_action('wp_ajax_nopriv_get_top_main', 'get_top_main_up');
  </code></pre>
  
  <p>This is what I've come up now but for some reason the response is the complete page syntax... (maybe because the URL is pointed to .ajaxurl), it doesn't seem to be calling the function.</p>