Javascript "development" and "production
I'm developing a simple application in Sinatra that makes many asynchronous calls. In my javascript code I have a variable that stores my domain for all calls. My problem is how to alter the value of the variable every time that I publish my application, for example:
var url = "http://localhost:9292"; //development
to
var url = "http://mysite.com" //production
I would like to automate this, to prevent errors in deployed application. Is it possible?
I thought about doing this in my "View" using ruby code, but do not know if it is cool.
S开发者_C百科orry my English.
Thanks.
Maybe you can use:
var url = 'http://' + document.domain;
document.domain get the name of the current domain.
Try with:
window.location.port
This get the domain port of the currernt website ;)
精彩评论