title: jQuery Ajax: Reference MVC controller url from App root
body: <p>I have an ASP.NET MVC web application running from <code>http://localhost/myappname</code>.  From jQuery, I make jQuery $.ajax() calls to return partial views based on some user action.  I usually call this from a view in the same controller that contains the function I am calling via Ajax. For example, a view in my Home controller has the following function (which works well):</p>
  
  <pre><code>function loadMyPartialView() {
      $.ajax({
        type: 'GET',
        url: 'Home/GetNavigationTreePV/',
        success: function (data) { onSuccess(data); },
        error: function (errorData) { onError(errorData); }
      });
      return true;
  }
  </code></pre>
  
  <p>This above url gets resolved to <code>http://localhost/myappname/Home/GetNavigationTreePV</code> and the partial view is returned correctly.</p>
  
  <p>Now, I am trying to use qUint to unit test my functions.  In this test case, I just want to verify I get to the end of the function and return true.  I have created a <code>QUNIT</code> controller and corresponding view (which loads my unit test JavaScript file).  From the test.js file that contains my unit tests, I try to make calls to the same functions that are in my Home views, like the one above.  But, since I am now running out of the <code>QUNIT</code> controller, the url gets resolved to <code>http://localhost/myappname/qunit/Home/GetNavigationTreePV</code>.</p>
  
  <p>I have tried changing the url of my ajax request to <code>/Home/GetNavigationTreePV/</code> (with the preceding forward slash), but when I do that I get the following url <code>http://localhost/myappname/Home/GetNavigationTreePV</code>.</p>
  
  <p>So, to be clear, I am trying to write my ajax request in a way that will always start from the root of my MVC application, and then append the url parameter given in my $.ajax() function.</p>
  
  <p>Is there an easy way to do that?  Am I going about this in a weird way?</p>