$.getJSON 在部署服务器中不工作

$.getJSON Not working in deployment server

我用这个 post 在 Asp Mvc 应用程序中安装了新版本的 Globalize。

所以在 _Layout.cshtml 我添加了这段代码

<script>

(function () {

    $(function () {
        $.when(
              $.getJSON("/Scripts/cldr/supplemental/likelySubtags.json"),
              $.getJSON("/Scripts/cldr/main/fr/numbers.json"),
              $.getJSON("/Scripts/cldr/supplemental/numberingSystems.json"),
              $.getJSON("/Scripts/cldr/main/fr/ca-gregorian.json"),
              $.getJSON("/Scripts/cldr/main/fr/timeZoneNames.json"),
              $.getJSON("/Scripts/cldr/supplemental/timeData.json"),
              $.getJSON("/Scripts/cldr/supplemental/weekData.json")
            ).then(function () {

                // Normalize $.get results, we only need the JSON, not the request statuses.
                return [].slice.apply(arguments, [0]).map(function (result) {
                    return result[0];
                });

            }).then(Globalize.load).then(function () {
                var culture = "fr";
                Globalize.locale(culture);
            });
    });
})();


</script>

但是当我在服务器中部署时它不起作用。

Ps:我在 web.config

中添加了这个
<system.webServer>
...
<staticContent>
  <remove fileExtension=".json"/>
  <mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>

</system.webServer>

请帮忙。

试试这个方法:

$.getJSON(@Url.Content("~/Scripts/cldr/supplemental/likelySubtags.json")),
$.getJSON(@Url.Content("~/Scripts/cldr/main/fr/numbers.json")),...

可能需要用双引号将其括起来,稍微尝试一下 @Url.Content,但我相信它会解决您的问题

$.getJSON("@Url.Content("~/Scripts/cldr/supplemental/likelySubtags.json")"),
$.getJSON("@Url.Content("~/Scripts/cldr/main/fr/numbers.json")"),...