JavaScript 相对 URL

发布于 2024-12-16 10:48:40 字数 936 浏览 1 评论 0 原文

我们在 IIS7 中有一个 MVC3 应用程序: http://mydomain.com/myapplication/

相对 URL 是什么在 javascript 中:

http://mydomain.com/myapplication/mycontroller/myaction

/mycontroller/myaction - 转到 http://mydomain.com/mycontroller/myaction

../mycontroller/myaction - 上升一级(在本例中也到 http://mydomain.com/mycontroller/ myaction)

mycontroller/myaction - 转到 http://mydomain.com/myapplication/mycontroller/myaction 当在本地主机上以开发人员身份运行但在服务器上运行时,会转到 http://mydomain.com/mycontroller/myaction

./mycontroller/myaction - 我认为是正确的,但这也不起作用!

We have an MVC3 application in IIS7: http://mydomain.com/myapplication/

What would be the relative URL in javascript for:

http://mydomain.com/myapplication/mycontroller/myaction

/mycontroller/myaction - goes to http://mydomain.com/mycontroller/myaction

../mycontroller/myaction - goes up one level (in this case also to http://mydomain.com/mycontroller/myaction)

mycontroller/myaction - goes to http://mydomain.com/myapplication/mycontroller/myaction when running as dev on localhost but on server goes to http://mydomain.com/mycontroller/myaction

./mycontroller/myaction - was what I figured would be right, but that didn't work either!

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

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

发布评论

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

评论(2

丑疤怪 2024-12-23 10:48:41

如果您在 ASP.NET MVC 中进行开发,您可以在服务器端设置 root var,如下所示:

<script language="javascript" type="text/javascript">
   var root = '<%= this.Request.ApplicationPath%>';
</script>

并在 JS 中使用它:

<script language="javascript" type="text/javascript">    
   img = root + '/someotherrootfile.js'
</script>

If you are developing in ASP.NET MVC you can set root var on server side like this:

<script language="javascript" type="text/javascript">
   var root = '<%= this.Request.ApplicationPath%>';
</script>

and use it in JS:

<script language="javascript" type="text/javascript">    
   img = root + '/someotherrootfile.js'
</script>
梦中的蝴蝶 2024-12-23 10:48:41

您只需列出文件名即可。

<script src="filename.js"></script>

如果我理解正确,您只需要列出不带前导斜杠的文件名或路径目录。

You would just list the file name.

<script src="filename.js"></script>

If I understand you correctly you would only need to list the filename or path directory with no leading slash.

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