title: Relative URLs in AJAX requests
body: <p>Why does Javascript treat relative URLs differently than standard HTML? Think of the following URL (or just browse to it): <a href="http://en.wikipedia.org/wiki/Rome" rel="noreferrer">http://en.wikipedia.org/wiki/Rome</a>.
  Open a Firebug console (or another Javascript console) and enter the following:</p>
  
  <pre><code>var x = new XMLHttpRequest();
  x.open("GET", "foo", true);
  x.send("bar");
  </code></pre>
  
  <p>Under my system the request is sent to "<a href="http://en.wikipedia.org/wiki/foo" rel="noreferrer">http://en.wikipedia.org/wiki/foo</a>". The "Rome" in the URL is simply ignored. The same request with a trailing slash in the URL ("<a href="http://en.wikipedia.org/wiki/Rome/" rel="noreferrer">http://en.wikipedia.org/wiki/Rome/</a>") appends the "foo" to the full URL.</p>
  
  <p>This seems to make it pretty hard to encode the correct URLs in Javascript. Are there any Javascript libraries that help to overcome this problem?</p>
  
  <p>(I asked a similiar <a href="https://stackoverflow.com/questions/4754559/relative-url-does-not-get-resolved-correctly-by-jquery">question</a> before, but more jQuery specific, where this also happens. I hope I get a better answer with this somewhat more library independent question.)</p>