title: XMLHttpRequest "PUT"
body: <p>I know how to <code>"GET"</code> data using <code>XMLHttpRequest()</code>, and would also like to use <code>XMLHttpRequest()</code> to <code>"PUT"</code> data to a file. The data I would like to <code>"PUT"</code> is just plain text. There is much on how to <code>"GET"</code> data, but I have done much research and have not found much on how to <code>"PUT"</code>data. There are a few questions online trying to do something similar but usually to <code>"POST"</code> instead, and none I found show a working model. Some say that for <code>"POST"</code>ing or <code>"PUT"</code>ing data, its <code>"Content-type"</code> must be <code>"application/x-www-form-urlencoded"</code> and never <code>"text/plain"</code>. I would like to do my request synchronously and not use Node.js instead. To what I have found, this (below) seems to be the way to <code>"PUT"</code> data, but does not work. </p>
  
  <p>How should data be <code>"PUT"</code> using <code>XMLHttpRequest()</code>?</p>
  
  <pre><code>var string = encodeURIComponent("Text String!");
  var req = new XMLHttpRequest();
  req.open("PUT", "example/data.txt", false);
  req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  req.setRequestHeader("Content-length", string.length);
  req.setRequestHeader("Connection", "close");
  req.send(string);
  </code></pre>
  
  <p>I have tried <code>"text/plain"</code> as the <code>"Content-type"</code>, but the browser console gives me a "syntax error" in the resource I want to replace or tells me "no element found" if the resource is blank.</p>