title: root url javascript
body: <p>I'm working on an .Net ASP MVC razor application</p>
  
  <p>The root url on the server being "myWebSite.com/myApp/" </p>
  
  <p>I need to find dynamically this url to have the right url to make some Ajax call to action like this</p>
  
  <pre><code>    $.ajax(
      {
          type: "POST",
          url: root + "/Controller/Action",
          data: ...
      }
  </code></pre>
  
  <p>I read a few things here and there but what I found doesn't work</p>
  
  <pre><code>"document.location.hostname" -&gt; "myWebSite.com"
  "location.host"              -&gt; "myWebSite.com"
  "window.location.pathname"   -&gt; "/myApp/"
  </code></pre>
  
  <p>Last one sounded promissing but if I navigate in the website :</p>
  
  <pre><code> for an url :  "myWebSite.com/myApp/Controller/Action?1" 
   "window.location.pathname"   -&gt; "/myApp/Controller/Action"
  </code></pre>