在JavaScript ASP.NET MVC的URL解析 [英] ASP.NET MVC resolve urls in javascript

查看:107
本文介绍了在JavaScript ASP.NET MVC的URL解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载了通过jQuery.load('/商务/标签'),使用我的本地网络服务器的时候效果很好的一些内容。但是,使用IIS时,这并不正确解析。我见过一对夫妇不同的方式来解决这个问题,如RESOLVEURL。什么是处理您的JavaScript解析网址的最佳方式?

I am loading up some content via jQuery.load('/Business/Tags'), which works well when using my local webserver. But when using iis this does not resolve correctly. I have seen a couple different ways to get around this such as ResolveUrl. What is the best way to handle resolving urls in your javascript?

推荐答案

我遇到了我的JavaScript的这个确切的问题。由于我的JavaScript也是其中被列入我的母版页单独的文件,我不能在我的情况下使用RESOLVEURL。

I ran into this exact problem with my JavaScript. Since my JavaScript was also in a separate file which was included in my Master Page, I couldn't use ResolveUrl in my case.

下面是我如何解决它在我的情况。我包括在我的脑海标签顶部下面的JavaScript在我的母版页:

Here's how I solved it in my case. I included the following JavaScript in my head tag in my Master Page at the top:

<script type="text/javascript">
    var baseUrl = "<%= Request.Url.GetLeftPart(UriPartial.Authority) %>";
</script>

我设置一个全局变量这是一个名为我所有的JavaScript文件访问的baseUrl。

I'm setting a global variable that's accessible to all my JavaScript files called baseUrl.

您code将随即成为:

Your code would then become:

jQuery.load(baseUrl + '/Business/Tags');

这篇关于在JavaScript ASP.NET MVC的URL解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆