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

javascript中的相对URL是什么:

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


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

../mycontroller/myaction-上升一个级别(在这种情况下,也上升到http://mydomain.com/mycontroller/myaction

mycontroller / myaction-在localhost上以dev身份运行时转到http://mydomain.com/myapplication/mycontroller/myaction,但在服务器上转到http://mydomain.com/mycontroller/myaction

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

最佳答案

如果您正在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>

关于javascript - Javascript相对URL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8153733/

10-11 13:55