jquery - How to make the code server ip agnostic in Javascript? -




whenever restart server ip changes, force me change ip address in code works properly. want make server ip agnostic, don't have change ip in code everytime restart server.

making url relative best solution here. , that's did , worked me. example: create new html file(index.html):

<html>   <head>     <script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>     <script src="script.js"></script>      </head>     <body>     make server ip agnostic     </body> </html> 

your javascript file(script.js):

var baseurl;  //global variable, can use in large codebase later. $.getjson('config.json',function(data){ baseurl = data.url; console.log(baseurl); }); 

your json file(config.json):

{ "url": "192.120.12.1/" } 

and work. when ever want can change url directly in config.json file.





wiki

Comments

Popular posts from this blog

elasticsearch - what is the equivalent data type for geo_point in hibernate search? -

Jenkins: find build number for git commit -

firebase - How to wait value in Ionic 2 -