asp.net-mvcgetjsonjquery-globalize

$.getJSON Not working in deployment server


I used this post Globalize error with local numbers on .Net MVC Project to install the new version of Globalize in Asp Mvc Application.

So In the _Layout.cshtml I added this code

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

But when i deploy in the server it doesn't work.

Ps: I added this in my web.config

<system.webServer>
...
<staticContent>
  <remove fileExtension=".json"/>
  <mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>

</system.webServer>

Please Help.


Solution

  • Try this way:

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

    Might need to wrap it around in double quotes, just play around a little with the @Url.Content but I believe it will solve your problem

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