title: how to save xml file with ajax and javascript
body: <p>I am trying to add an element to an xml file. I have checked the program with debugger and I saw it really adds the element to the xml file but when I stop the running the file didn't saved any changes.
  here is the javascript file:</p>
  
  <pre><code>var xmlhttp = LoadXMLHttp();
  var xmlDoc=LoadXMLDoc("XMLFile.xml");;
  function LoadXMLHttp() {
      var xmlHttp;
      if (window.XMLHttpRequest)
          xmlHttp = new XMLHttpRequest();
      else
          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      return xmlHttp;
  }
  function LoadXMLDoc(FileName) {
      xmlhttp.open("GET", FileName, false);
      xmlhttp.send(null);
      return xmlhttp.responseXML;
  }
  function CreateXmlElement() {
      if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
          newMessageElement = xmlDoc.createElement("message");
          newTextElement = xmlDoc.createElement("text");
          newText = xmlDoc.createTextNode("I am fine");
          newTextElement.appendChild(newText);
          newMessageElement.appendChild(newTextElement);
          x = xmlDoc.documentElement;
          x.appendChild(newMessageElement);
      }
  }
  function AddXMLElement() {
      xmlhttp.open("POST", "Default.aspx", true);
      xmlhttp.setRequestHeader("Accept", "text/xml");
      xmlhttp.onreadystatechange = CreateXmlElement;
      xmlhttp.send(xmlDoc);
  }
  </code></pre>
  
  <p>And here is the xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;conversation&gt;
    &lt;message&gt;
      &lt;text&gt;Hi&lt;/text&gt;
    &lt;/message&gt;
    &lt;message&gt;
      &lt;text&gt;How are you?&lt;/text&gt;
    &lt;/message&gt;
  &lt;/conversation&gt;
  </code></pre>
  
  <p>By the way:</p>
  
  <ol>
  <li><p>I don't know jquery or <code>php</code> but I do know <code>asp.net</code></p></li>
  <li><p>If I change the open url to "XMLFile.xml", I get an error message that says "method not allowed".</p></li>
  <li><p>I have a button that activates the <code>AddXMLElement()</code> function.</p></li>
  </ol>