When uploaded to a hosted server the following code is successfully turned to http://myexample.com/otherpartsofpath :
ajax: {
url: 'http://' + window.location.hostname + '/otherpartsofpath',
type: 'GET',
...
But when rendered on the local computer it gives an error. That’s why in this case I should define the URL explicitly:
ajax: {
url: 'http://localhost:10930/otherpartsofpath',
type: 'GET',
...
How could I make the code to work locally without explicitly defined URL?
Using a relative path
/testwill always result in the correct protocol, hostname and port. Thus, for convenience you could just always use:When run on
http://test.com/directory/test.htmlit ishttp://test.com/otherpartsofpath.When run on
http://localhost:1234/directory/test.htmlit ishttp://localhost:1234/otherpartsofpath.