Hey all,
Its time for another very simple question that I can't find an elegant solution for. Basically, I have an app that is using a jQuery Ajax call. In this call, you have to specify a URL path for the service that you are calling. In this instance, I am needing to call this JavaScript function from multiple files in my application and those files are on differing levels of the folder structure.
Here's the question, how would you elegantly handle this scenario so that you can call the JS function from any location in your app. Here are my constraints:
1) I am running on Asp.Net 4.0. 2) My current environment has a local, Dev, Test, and Prod Environment (hard-coding the URL path will not work).
Code Snippets:
function MakeTheCall() {
$.ajax({
type: "POST",
url: "Services/FileName.asmx/Handler", //Path in Question
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {
},
error: function(xmlHttpRequest, status, err) {
}
});
}
I would like to be able to call this function (which is in an external JavaScript file) from files in different directory levels, such as:
1) http://SomeDomain.com/SomeDir/CallingFile.aspx 2) http://SomeDomain.com/CallingFile.aspx
Any suggestions? I can think of a couple different scenarios for pulling this off, but most revolve around creating a JavaScript variable and setting its value in C#. Hopefully there's a better way?
Thanks!