Skip to content

Instantly share code, notes, and snippets.

@calexandrepcjr
Created May 19, 2017 20:18
Show Gist options
  • Save calexandrepcjr/c263ff735b711df1cbaa19d911c8222b to your computer and use it in GitHub Desktop.
Save calexandrepcjr/c263ff735b711df1cbaa19d911c8222b to your computer and use it in GitHub Desktop.
A different way to work urls into ajax calls
this.pathname = window.location.pathname.split('/');
//Normally in the dev environment the project will be inside a path into htdocs dir
if (window.location.host == 'localhost'){
this.subDirs = this.pathname.length - 3;
} else {
this.subDirs = this.pathname.length - 2;
}
this.baseUrl = '../';
this.baseUrl = this.baseUrl.repeat(this.subDirs);
self.path = this.baseUrl + 'path or source that you want';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment