How do I SET a Cookie (header) with XMLHttpRequest in JavaScript?
<p>I'm trying to set a Cookie in a XSS request using XMLHttpRequest.</p>

<p>I found the <a href="http://www.w3.org/TR/XMLHttpRequest/" rel="nofollow">XMLHttpRequest Specification</a>, and section 4.6.2-5 does seem to suggest that setting Cookie, Cookie2, and some other headers are not allowed, but I was hoping there was a work around.</p>

<p>My (jQuery) code is below, but the resulting query fails as the cookie is NOT set.</p>

<pre><code>$.ajax( {
  type : "POST",
  url : URL,
  data: SOAP_INBOX_MAIL_QUERY,
  dataType : "xml",
  async: false,
  beforeSend : function(xhr) {  
    var cookie = credentials["COOKIE"];
    console.info( "adding cookie: "+ cookie );          
    xhr.setRequestHeader('Cookie', cookie);
  },
  success : function(data, textStatus, xmLHttpRequest){


  },
  error : function(xhr, ajaxOptions, thrownError) {
    credentials = null;
  }
});
</code></pre>
