在Javascript中获取相对路径

发布于 2024-09-06 19:39:36 字数 596 浏览 1 评论 0原文

我有这个应用程序,我使用 IHttpHandler 将 JSON 数据提供给我的 JavaScript 方法。

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

这在我的“localhost”网络服务器上运行良好,但我也有一个临时服务器供我的客户使用。 http://staging.infinitas.ws/ClientSite/

我遇到的问题是,当应用程序托管在临时服务器上时,theSource 映射不正确(包含/ClientSite/)。我可以做一些类似于 String.Replace 的事情,但我正在寻找一种更优雅的方式来实现这一点。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我是男神闪亮亮 2024-09-13 19:39:36

尝试

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

try

Page.ResolveClientUrl("~/RegionsAutoComplete.axd")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文