I have a bunch of static javascript files that process AJAX functions to request various parts of my application, and I am deploying several versions of my application, so I might have something like the following:
https://www.myurl.com/projectName/ - production release https://www.myurl.com/projectName_alpha/ - current alpha release https://www.myurl.com/projectName_beta/ - current beta release https://www.myurl.com/projectName_unstable/ - current development build
so if I have a controller "foo" that I want to make an AJAX call to, I cannot hardcode /projectName/foo
as a URL (as this would always indicate a product release). I am currently embedding a script in each of my views, which gets the base URL of the project as a global variable:
<script type="text/javascript"> </script>
and then specify that in javascript files:
var url = baseUrl + 'foo/';
This is a functional but ugly solution, and I would prefer not to pollute the global namespace if I can avoid it. Does anyone have any suggestions on how I could implement a better workaround?
To clarify: the solution must be workable for any type of request, be it AJAX-based or not-call window.open
, setting the src
attribute of the <img>
and making an AJAX call the controller should work with the solution. It should also be applied no matter what base URL or how many layers it contains, for example:
https://www.myurl.com/ https://www.myurl.com/projectName/ https://www.myurl.com/projectName_alpha/1.2.3/
must be detected correctly.
source share