title: Call .php file with an ajax request - wordpress
body: <p>I am trying to call a php file from an ajax request in wordpress. The problem I am encountering is that the ajax request requires a path to the php file. I am unsure of where to place this php file in my wordpress installation. Further, this file cannot be included inline because I need to call this php file only when the user decides to call it. I don't use jquery right now but would be open to using it as I'm pretty sure that's client side only so the server wouldn't have to be involved. </p>
  
  <p>As an example of something I would like to do let's try this with a form. This example was taken from <code>http://thisinterestsme.com/ajax-form-submission-php/</code>.</p>
  
  <p>I would include this in the webpage. </p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;Example Ajax PHP Form&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;form id="my_form_id"&gt;
              Your Email Address: &lt;input type="text" id="email" /&gt;&lt;br&gt;
              &lt;input type="submit" /&gt;
          &lt;/form&gt;
  
          &lt;script src="//code.jquery.com/jquery-1.11.3.min.js"&gt;&lt;/script&gt;
          &lt;script&gt;
              $(document).ready(function(){
                  $('#my_form_id').on('submit', function(e){
                      //Stop the form from submitting itself to the server.
                      e.preventDefault();
                      var email = $('#email').val();
                      $.ajax({
                          type: "POST",
                          url: 'submission.php',
                          data: {email: email},
                          success: function(data){
                              alert(data);
                          }
                      });
                  });
              });
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Then elsewhere on the server I would have this file. The problem is I don't know where to place this file or what path to give the ajax request above. </p>
  
  <pre><code>&lt;?php
  $emailAddress = false;
  if(isset($_POST['email'])){
      $emailAddress = $_POST['email'];
  }
  
  echo 'Received email was: ' . $emailAddress;
  ?&gt;
  </code></pre>