title: Wordpress ajax post to same page - with only admin panel access
body: <p>I only have admin panel access (no file level access) to a wordpress site. I am adding php code using this plugin <a href="https://wordpress.org/plugins/shortcode-exec-php/" rel="nofollow">Shortcode Exec PHP</a> and adding my jquery into the text editor. </p>
  
  <p>Everything is working fine. But now that I want to have an ajax call where my ajax post url will be <code>window.location.href</code> and will point to the code within my shortcode exec php <code>if(isset($_POST)){ echo "Yes!" }</code> , I am getting the entire page as a response. Note that I am new to wordpress and testing using a draft.</p>
  
  <p>Please let me know what I am doing wrong. Appreciate suggestions on better practices to achieve this. Following is my code:</p>
  
  <p>//jquery</p>
  
  <pre><code>  $.ajax(
                     {
                         type: 'POST',
                         url: window.location.href,
                         dataType: 'json',
                         cache: false,
                         data:{
                           action: 'test'
                         },
                         success: function(response)
                         {
                            alert('success');
  
                         },
                         error: function(xhr, textStatus, errorThrown)
                         {
                             alert('error');
                         }
                     });
  </code></pre>
  
  <p>//php</p>
  
  <pre><code>if(isset($_POST)){ echo "Yes!"; return "true"; }
  </code></pre>
  
  <p>Thank you.</p>