title: How to avoid hard-coding the application context path in js/ajax scripts
body: <p>I use <strong>Spring MVC</strong> and <strong>Javascript/ajax</strong>. <strong>I have an issue with the way my ajax scripts refer to a server-side resource.</strong></p>
  
  <p>Say I have <strong>two pages</strong> that need to use <strong>the same server-side resource</strong> through ajax:</p>
  
  <p>The url for the first page is:</p>
  
  <ul>
  <li><code>/myapp/advertisement/28/edit</code></li>
  <li><code>/myapp/signup</code></li>
  </ul>
  
  <p>Say the server-side resource that my ajax script need to use is: </p>
  
  <ul>
  <li><code>/myapp/geolocation/addressAutocomplete</code></li>
  </ul>
  
  <p>As of now, I have <strong>hard-coded</strong> the application context path i.e. <strong><code>/myapp</code></strong> in my ajax script.</p>
  
  <p><strong>If and when my application context path changes I need to update is all over my scripts.</strong></p>
  
  <p>Is there a solution to that?</p>