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!
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>
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.
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.