title: PHP script return responseText to AJAX From POST? Want To Return Message with Ajax POST
body: <p>I am trying to make a scheme where Ajax calls upload.php and upload.php will return success or failure in a message. I tried using echo "successs" in the php script, hopeing that xhr.responseText would receive the message. But instead alert(xhr.responseText) is a blank line. Then it occured to me, does xhr.responseText only work with GET and not POST? If this is it, how can I have it to where the php script can return a custom message? I do not  want to use the HTTP status codes...I rather learn how to do custom messages if possible. </p>
  
  <p><strong>No Jquery please.</strong> </p>
  
  <pre><code>&lt;?php
  $tmp_name = $_FILES['file1']['tmp_name'];
  $path = "/trunk";
  $name = $path . DIRECTORY_SEPARATOR . $_FILES['file1']['name'];
  $success = move_uploaded_file($tmp_name, $name);
  if ($success) {
      echo "good";
  } else {
      echo "bad";
  }
  ?&gt;
  }
  
  function uploadPHP() {
      var xhr = new XMLHttpRequest(),
         form = document.getElementById("uploadForm");
  
      xhr.open("POST", "php/upload.php", true);
      xhr.send(new FormData(form));
      alert(xhr.responseText);
  }
  </code></pre>