title: How to reference Wordpress directory constants inside Javascript
body: <p>I am building a custom Wordpress plugin and within it, i am making an ajax request to a PHP file to do a simple query.  I continually get some variation of (hyphens included but not in the original, so your browser won't take you to localhost):
  &quot;POST http:-//-localhost:-8888-/xxx.php 404 (Not Found)</p>
  <p>Here is the skeleton of my ajax request:</p>
  <pre><code>if(selID){
          $.ajax({
              type: 'POST',
              url:  &quot;xxx.php&quot;,
              data: 'loc_id='+selID,
              success:function(html){
                  $('#selOne').html(html);
                  $('#selTwo').html(html);
              }
          }); 
      }else{
         /* Other non-relevant stuff.
      }
  </code></pre>
  <p>I understand that my php file is not in the same directory as my javascript file, so i'm trying to figure out how to reference it.  I've tried every variation of absolute paths and relative (../../..  and so on....) paths that i can think of and i keep getting the same error.</p>
  <p>I've researched this some and found a suggestion that you could insert PHP code in Javascript (something i've never attempted before actually) and came across the idea to use something like this for the &quot;url&quot; parameter:</p>
  <pre><code>url: &quot;&lt;?php echo plugins_url(); ?&gt;&quot;;
  </code></pre>
  <p>I didn't know that you could even attempt that honestly, so i tried it, but all it seems to do for me is print what is in the quotes.  For example:</p>
  <pre><code>var pluginUrl = &quot;&lt;?php echo plugins_url(); ?&gt;&quot; ;
      alert ('plugin dir ' + pluginUrl);
  </code></pre>
  <p>simply returns what is inside the double quotes.  Javascript doesn't seem to pass off the request to PHP at all.  So, i've not even tried working with it within my ajax request.  Does this in fact work?</p>
  <p>My path to my JS file is thus:
  /Applications/MAMP/htdocs/MyDemo/wp-content/plugins/xxx.php</p>
  <p>My path to my desired xxx.php file is thus:
  /Applications/MAMP/htdocs/MyDemo/wp-content/themes/myTheme/static/my-js.js</p>
  <p>For me, it would seem that if i went the relative path way (i prefer an absolute path solution) would look something like:</p>
  <pre><code>url:  &quot;../../../plugins/xxx.php&quot;,
  </code></pre>
  <p>should work, but no dice.  I have even tried putting the php file in the same directory as my javascript file, same error and STILL no love.</p>
  <p>I'd like advice on how to fix my situation:
  a) get it to work correctly (of course)
  b) code it correctly according to good wordpress standards, meaning that i don't want to touch the functions.php file (unless i absolutely have to in order to get there) and i'd like to know the proper WP way of referencing paths in this situation.</p>
  <p>thank you!</p>