0

I am not sure if my heading makes sense. This code example will make things clear, perhaps. I am hosting a simple Web service using Tomcat. I also have some HTML/JavaScript making calls to the web service. I use the XMLHttp for the same. This is an example:

var xmlhttp=new XMLHttpRequest();
xmlhttp.open('GET','http://mywebservice.com/rest/main',false);  
//xmlhttp.open('GET','http://localhost:8080/appName/rest/main',false);  
xmlhttp.send();
getNames(xmlhttp);

Each time I deploy this web service on a certain Tomcat instance (local or cloud), the URL in the xmlhttp.open() call needs to be manually modified. See the commented code.

Is it possible to fetch this base URL programmatically ?

pushkarnk
  • 323
  • 3
  • 10

1 Answers1

0

plese refer How to extract base URL from a string in JavaScript?

pathArray = location.href.split('/');
protocol = pathArray[0];
host = pathArray[2];
url = protocol + '//' + host;

hope it will help

Community
  • 1
  • 1
syms
  • 413
  • 2
  • 12