title: Include PHP file using jQuery or Javascript
body: <p>I have a Javascript file that submits a form and loads an alert etc. Now I want to add functionality to call or get a <code>.php</code> file, I tried using <code>$.get("mail.php");</code> but it doesn't seem to work.</p>
  
  <p>Javascript Code: </p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>$('#myform').on('submit', function(e){
      e.preventDefault();
      $.get($(this).attr('action') + $(this).serialize());
      alert("Thank You! \nTop Up for: &lt;?php echo "$username" ?&gt; Purchased Successfully");
      $.get("mail.php");  //this is the added part to get mail.php//
      location.reload();
  </code></pre>
  
  <p>PHP - <code>mail.php</code>: </p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  $to = "stephan@mail.co.za";
  
  $headers = "From: website mail \r\n";
  
  $email_body = "has just toped up his account.\n".
  
  $email_subject = "User Topup Alert";
  
  mail($to,$email_subject,$email_body,$headers);
  
  ?&gt;
  </code></pre>