title: Get a PHP file to return text/plain to AJAX call
body: <p>I'm working on a simple HTML form that either detects if a record exists (in an XML file) and populates all the fields OR detects that the form doesn't exist and on submit, creates the record (or modifies the current one if it's been modified)</p>
  
  <p>I'm working on the part now that would add a non existing record and/or modify an existing one.</p>
  
  <p>The AJAX calls a PHP file, and in the PHP file I'd like to check if the record exists or not and perform the appropriate operations accordingly. I would like the user of the form to be informed (no pun intended) of what operation was carried out (i.e. "Added the Record" or "Modified the Record").</p>
  
  <p>To start with, all I have my PHP doing right now is returning the text <code>added</code>. I want to see if I can get "Added the Record" to properly display in original HTML file.</p>
  
  <p><strong>EXPECTED:</strong> When I click <code>Submit</code>, I expect the message "Added the Record" or "Modified the Record" to appear under the form, depending on the return from the PHP file.</p>
  
  <p><strong>THE ERROR:</strong> Now, when I click <code>Submit</code>, the form resets itself, adds all the parameters to the URL and I don't get any message from the AJAX request.</p>
  
  <p>Here's my code:</p>
  
  <p>HTML Page:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html&gt;
      &lt;head&gt; 
          &lt;script type="text/javaScript"&gt;
              function checkID(val){
                  if (val.value.length != 6) //Since student ID's are six digits
                      return;
                  //inID = val.value;
                  //if (inID.length &lt; 6) return;
  
                  xhr = new XMLHttpRequest();
                  xhr.open('GET', 'processor.php?studentID=' + document.forms[0].elements[0].value);
                  xhr.onreadystatechange = function() {
                      /**
                      if (xhr.readystate != 4 || xhr.status != 200){
                          document.getElementById("status").innerHTML = "&lt;p&gt; Not Done Yet&lt;/p&gt;";
                      }
                      **/
                      if (xhr.readyState === 4 &amp;&amp; xhr.status === 200){
                          document.getElementById("status").innerHTML = "";
                          parse(xhr.responseXML); 
                      }
                  }
                  xhr.send();
                  document.getElementById("status").innerHTML = "&lt;p&gt; Not Done Yet&lt;/p&gt;";
              }
              function parse(xml){
                  if (xml == null) alert("Null!");
                  var student = xml.getElementsByTagName('student');
                      if (student.length == 0) alert("No Student's Found with that ID");
                  var content = student.item('0');
                      var name = content.getElementsByTagName('fullname');
                      name = name.item(0).childNodes[0].nodeValue;
                      document.forms[0].elements[1].value = name;
  
                      var phone = content.getElementsByTagName('phone');
                      phone = phone.item(0).childNodes[0].nodeValue;
                      document.forms[0].elements[2].value = phone;
  
                      var email = content.getElementsByTagName('email');
                      email = email.item(0).childNodes[0].nodeValue;
                      document.forms[0].elements[3].value = email;
  
              }
              function addOrModify(curr){
                  xhr2 = new XHRHttpRequest();
                  xhr2.open('GET', 'addOrModify.php'); //?studentID=' + document.forms[0].elements[0].value);
                  xhr2.onreadystatechange = function(){
                      if (xhr2.readyState === 4 &amp;&amp; xhr2.status === 200){
                          if (xhr.responseText == "added") {document.getElementById("status").innerHTML = "&lt;p&gt;Added the Record&lt;/p&gt;"};
                      }
                  }
                  xhr.send();
                  return false;
              }
  
          &lt;/script&gt;
          &lt;style type="text/css"&gt;
              #container {
                  margin: 0 auto;
                  padding: 30px;
                  text-align: center;
              }
              .centerp {
                  font-size: 150%;
                  text-align: center;
              }
              table {
                  align: center;
              }
          &lt;/style&gt;
          &lt;title&gt;Student Profile&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;p class="centerp"&gt; Student Profiles &lt;/p&gt;
          &lt;div id="container"&gt;
              &lt;form&gt;
                  &lt;table align="center"&gt;
                      &lt;label&gt;
                          &lt;tr&gt;
                              &lt;td&gt;Student ID&lt;/td&gt; 
                              &lt;td&gt;&lt;input type="text" name="studentID" onblur="checkID(this)"&gt; &lt;/input&gt;&lt;/label&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/label&gt;
                      &lt;label&gt;
                          &lt;tr&gt;
                              &lt;td&gt;Name&lt;/td&gt; 
                              &lt;td&gt;&lt;input type="text" name="name" id="name"&gt; &lt;/input&gt;&lt;/label&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/label&gt;
                      &lt;label&gt;
                          &lt;tr&gt;
                              &lt;td&gt;Phone&lt;/td&gt; 
                              &lt;td&gt;&lt;input type="text" name="phone"&gt; &lt;/input&gt;&lt;/label&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/label&gt;
                      &lt;label&gt;
                          &lt;tr&gt;
                              &lt;td&gt;Email&lt;/td&gt; 
                              &lt;td&gt;&lt;input type="text" name="email"&gt; &lt;/input&gt;&lt;/label&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/label&gt;
                          &lt;tr&gt;
                              &lt;td&gt; &lt;input type="submit" onclick="return addOrModify()"&gt; &lt;/input&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt; &lt;div id="status"&gt;
                                  &lt;/div&gt; &lt;/td&gt;
                          &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Simple PHP page:</p>
  
  <pre><code>&lt;?php
  
  
  aOm();
  function aOm(){
      header("Content-type: text/plain; charset=utf-8");
      echo "added";
  }
  
  ?&gt;
  </code></pre>