title: Calling a function from ajax in WordPress
body: <p>I have a category list in the WP job manager and I have created a function in the functions.php file</p>
  
  <pre><code>function category_select_list(){
      $cat_list = '';
      foreach ( get_job_listing_categories() as $cat ) {
         $cat_list .= '&lt;option value="'. esc_attr( $cat-&gt;slug ).'"&gt;'.esc_html( 
         $cat-&gt;name ).'&lt;/option&gt;';
      }
  
     echo  $cat_list;
     exit();
   }
  add_action('wp_ajax_nopriv_category_select_list', 'category_select_list');
  add_action('wp_ajax_category_select_list', 'category_select_list');
  </code></pre>
  
  <p>then in my site.js file, I check to see if a form is in the page and then make an ajax call to return the data from the function.</p>
  
  <pre><code>jQuery(document).ready(function() { // wait for page to finish loading
  if($('#mc4wp-form-1').length){
       jQuery.ajax({
          type: "POST",
          url: "/wp-admin/admin-ajax.php",
          data: {
              action: 'get_category_list'
          },
           success:function(output){
               alert(output);
           },
           error: function(errorThrown){
               alert(errorThrown);
           }
       });
     }
  });
  </code></pre>
  
  <p>The ajax is alerting a zero, not an error. I don't know what the issue is. I have changed the php function to just echo a "hello" to test that it's not the php function but it still alerts a '0'.</p>