简体   繁体   中英

Get relative path in Javascript

I've got this app where I'm using an IHttpHandler to serve JSON data to my JavaScript method.

  var theUrl = location.href;
  var txtCity = '#<%= txtForSaleCity.ClientID %>';
  var hidCity = '#<%= hiddenForSaleCityID.ClientID %>';
  var theSource = '<%= Page.ResolveUrl("~/RegionsAutoComplete.axd")%>?PID=<%= hiddenBusinessProvince.value %>';

This works fine on my "localhost" webserver, but I've also got a staging server for my clients to use. http://staging.infinitas.ws/ClientSite/

The problem that I'm having is that when the app is hosted on the staging server, the theSource is mapped incorrectly (contains /ClientSite/). I could do something like a String.Replace but I'm looking for a more elegant way of achieving this.

尝试

Page.ResolveClientUrl("~/RegionsAutoComplete.axd")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM