title: Relative Path Problems in Javascript Ajax call
body: <p>Okay, I have a JavaScript file with the following functions:</p>
  
  <pre><code>function AskReason() {
      var answer = prompt("Please enter a reason for this action:", "");
      if (answer != null)
          DoReason(answer);
  }
  
  function createXMLHttpRequest() {
      try {
          return new XMLHttpRequest();
      }
      catch (e)
      { alert('XMLHttpRequest not working'); }
      try {
          return new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      { alert('Msxml2.XMLHTT not working'); }
      try {
          return new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      { alert('Microsoft.XMLHTTP not working'); }
      alert("XMLHttpRequest not supported");
      return null;
  }
  
  function DoReason(reason) {
      var xmlHttpReq = createXMLHttpRequest();
      var url = "/Shared/AskReason.ashx?REASON=" + reason;
      xmlHttpReq.open("GET", url, true);
      xmlHttpReq.send(null);
  }
  </code></pre>
  
  <p>This line:</p>
  
  <pre><code>    var url = "/Shared/AskReason.ashx?REASON=" + reason;
  </code></pre>
  
  <p>Is what is causing the problem.</p>
  
  <p>In VS 2010 debugging the app - this call works to my ashx handler.</p>
  
  <p>When I move the project to a virtual directory - example <code>http://localhost/myapp</code></p>
  
  <p>this code will break and I have to change the javascript to this:</p>
  
  <p><code>var url = "http://localhost/myapp/Shared/AskReason.ashx?REASON=" + reason;</code> </p>
  
  <p>Any ideas on how I can fix this to work in both environments or just accept the manual change when I deploy apps to servers?  </p>
  
  <p>Thanks,
  Mike</p>