In my ASP.net web project, I\'ve written the following Javascript code in a .js file:
function getDeviceTypes() {
var deviceTypes;
$.ajax({
a
You've got two options:
Build a configuration/ preferences object in JavaScript which contains all your environment specific settings:
var config = {
base: <% /* however the hell you output stuff in ASPX */ %>,
someOtherPref: 4
};
and then prefix the AJAX url with config.base
(and change the value for config.base
whether you're on a dev/ testing/ deployment server.)
Use the
Personally, I'd go for option 1. You'll most likely find that config object coming in handy elsewhere.
Obviously the config object will have to be included in a part of your site where server-side-code is evaluated; a .js
file won't cut it without configuring your server. I always include the config object in the HTML ; its a small config object, whose contents can change on each page, so it's perfectly warrented to stick it in there.