title: How to edit/write back a JSON file hosted on a localhost using XMLHttpRequest() post method
body: <p>I am able to use the <code>XMLHttpRequest()</code> <code>GET</code> method to retrieve the data from the <code>.json</code> file, but when I try to use POST to update it, I receive a <code>404</code> error (Even though I can access the json file by simply typing in <code>localhost:8080\data.json</code></p>
  
  <p>I'm not sure why this is happening. The error is shown below:
  <code>POST</code> <code>http://localhost:8080/data.json</code> 404 (Not Found)</p>
  
  <p>I'm hosting the main html, and js files using node.js and express. I'm also using sockets to connect between the client side and server side. I've shown the two functions- the <code>GET</code> which works perfectly fine, and the POST which is not working.</p>
  
  <p>I'm wondering whether it is a permissions or browser security issue? (I'm using chrome)</p>
  
  <pre><code>function init(){
  var xobj = new XMLHttpRequest();
  xobj.open("GET","data.json");
  xobj.onload = function(){
      if(xobj.status===200 &amp;&amp; xobj.readyState ===4){
          person = JSON.parse(xobj.responseText); 
          if(person){//not sure if this check helps
              for(var i=0;i&lt;person.things.length;i++){
                  place.insertAdjacentHTML('beforeend',"&lt;p&gt;"+  person.things[i].text +"&lt;/p&gt;");
              }
          }
      }else{
          console.log("error getting data");
      }
  }
  xobj.send();
  }
  
  function sendDataToFile(data){
  console.log(data);
  //write to data.json
  var xobj = new XMLHttpRequest();
  
  xobj.open("POST","data.json",true);
  xobj.setRequestHeader("Content-type", "application/json");
  xobj.onload = function(){
      if(xobj.status===200 &amp;&amp; xobj.readyState ===4){
  
      }else{
          console.log("error getting data");
      }
  
  }
  person.things.push({text:data}); //pushing new data
  var sendString = JSON.stringify(person);//convert to json object
  console.log(sendString);
  xobj.send(sendString); //send
  }
  </code></pre>
  
  <p>Any help or suggestions would be appreciated!</p>
  
  <p>Thanks. </p>