title: Get wordpress posts array using ajax, php to jquery
body: <p>I am trying to write some code to retrieve wordpress posts to jquery using Ajax</p>
  
  <p>I am just learning so have been alerting to the screen.  This is what i have so far: </p>
  
  <p>test.js</p>
  
  <pre><code>  jQuery(document).ready(function($){
     var test_name = "testname";    
     $.ajax({
       url:'/wp-content/plugins/myPlugin/test.php',
       data: {name:test_name},
       type: 'POST',
       cache: false,
       success: function(data){
         alert(data);
       },
       error: function(data){
         alert('something went wrong');           
       }
     });
  });
  </code></pre>
  
  <p>test.php</p>
  
  <pre><code>&lt;?php
  $post_args = array(
      'post_type'  =&gt; 'products',
      'numberposts' =&gt; -1
  );
  $myProducts = get_posts($post_args);
  echo $myProducts;
  ?&gt;
  </code></pre>
  
  <p>Can someone point me in the right direction, I can receive strings back from the test.php, so i know the test.php file is being processed.  Thank you for any help/explanations</p>