ajax and relative urls
ajax, jquery, xmlhttprequest
Solution
Not sure if this is related, but when jQuery ajax builds relative urls, it matters if the current page url ends with "/" or not
If you invoke a page without an ending `/`:
http://atlas/Reporter
the relative urls from ajax calls on that page are ignoring the last segment:
http://atlas/_relative_url_passed_to_ajax
If you end with `/`:
http://atlas/Reporter/
the relative urls are using the last path segment `Reporter`:
http://atlas/Reporter/_relative_url_passed_to_ajax
Problem
I really don't get this. I have the following 'get' request: ``` $.ajax( { url: "api/getdirectories/", dataType: 'json', success: function ( data ) { // Do stuff } } ); ``` This is in a page served up to me by my staging server, `http://atlas/Reporter`. On my local dev box, this works, and in looking at fiddler I see the correct URL `http://localhost/Reporter/api/getdirectories`. On the staging server however the request is to `http://atlas/api/getdirectories`, which is invalid and I get a 404 error. Why is the 'Reporter' part of my path being dropped on the staging server? In looking at the document, the URL, baseURI, documentURI are all `http://atlas/Reporter`, and the domain is `atlas`. Exactly the same as on my local dev box (except it is all 'localhost' instead of 'atlas'. This problem has plagued me for a while now. I think I have it figured out and all is good, and then I run into it again. I don't think it is a same origin policy issue, as I am requesting the data from the same site the page originated from. So, how exactly is the full url determined for the request? It doesn't seem to be one of the document variables mentioned above being concatenated onto my relative URL... so how does this work? `Edit: Removed the '/' from the URL as it is distracting from the real issue- behavior is the same with or without it.`