title: Wordpress ajax returning html
body: <p>Am using WordPress ajax to load the sub-categories dynamically.</p>
  
  <p>Here's my code</p>
  
  <p>Php code </p>
  
  <pre><code>  function techento_getsubcat() {
    $category_name = $_POST['catname'];
    $cat_id = $_POST['catid'];
    return wp_dropdown_categories( 'show_option_none=Choose a Sub              Category&amp;tab_index=10&amp;taxonomy=category&amp;hide_empty=0&amp;child_of=' . $cat_id . '' );
  
    }
    add_action('wp_ajax_techento_getsubcat', 'techento_getsubcat');
    add_action('wp_ajax_nopriv_techento_getsubcat', 'techento_getsubcat');
  </code></pre>
  
  <p>Jquery</p>
  
  <pre><code>        jQuery(document).ready(function(){
     $('#cat').change(function(e){
     alert("changed");
  
      $.ajax({
          type: 'POST',
          dataType: 'json',
          url: pcAjax.ajaxurl ,
          data: { 
              'action': 'techento_getsubcat', //calls wp_ajax_nopriv_ajaxlogin
            'catname':    $('#cat option:selected').text(), 
              'catid':    $('#cat option:selected').val() },
          success : function(response){
                   alert(response);
               console.log(response);
  
             $("#subcats").html(response);
  
          }
      });
      e.preventDefault();
  
        });
    });
  </code></pre>
  
  <p>The problem with the above code is that php returns the raw html irrespective of the  thing asked to return</p>
  
  <p>even if set it to </p>
  
  <pre><code>    return true;
  </code></pre>
  
  <p>it then returns the raw html of subcategories generated plus '0'</p>