title: Set a request header in JavaScript
body: <p>It seems that I am unable to change most request headers from JavaScript when making an AJAX call using XMLHttpRequest.  Note that when <code>request.setRequestHeader</code> has to be called after <code>request.open()</code> in Gecko browsers (see <a href="http://ajaxpatterns.org/Talk:XMLHttpRequest_Call" rel="noreferrer">http://ajaxpatterns.org/Talk:XMLHttpRequest_Call</a>).  When I set the <em>Referer</em>, it doesn't get set (I looked at the request headers sent using Firebug and Tamper Data).  When I set <em>User-Agent</em>, it messed up the AJAX call completely. Setting <em>Accept</em> and <em>Content-Type</em> does work, however. Are we prevented from setting <em>Referer</em> and <em>User-Agent</em> in Firefox 3?</p>
  
  <pre class="lang-js prettyprint-override"><code>var request = new XMLHttpRequest();
  var path="http://www.yahoo.com";
  request.onreadystatechange=state_change;
  
  request.open("GET", path, true);
  request.setRequestHeader("Referer", "http://www.google.com");
  //request.setRequestHeader("User-Agent", "Mozilla/5.0");
  request.setRequestHeader("Accept","text/plain");
  request.setRequestHeader("Content-Type","text/plain");
  
  request.send(null);
      function state_change()
  {
  if (request.readyState==4)
    {// 4 = "loaded"
    if (request.status==200)
      {// 200 = OK
      // ...our code here...
      alert('ok');
      }
    else
      {
      alert("Problem retrieving XML data");
      }
    }
  }
  </code></pre>