title: Can headers be sent in an AJAX request?
body: <p>Can I call the server to set a new cookie with an AJAX request (that is, after the page has already loaded)?</p>
  
  <p>For example, when a visitor hits a link, ajax would open a php file that sets a new cookie like this:</p>
  
  <pre><code>setcookie('cookiename', 'true', time()+3000, "/",'...');
  </code></pre>
  
  <p>But this is done after the html (the page containing the actual <code>&lt;a&gt;</code> tag pressed) was rendered. Is it nevertheless ok to set cookies in ajax? (maybe because the php file loaded is separate from the original html page).</p>