i18next load json error(404 Not Found)

六眼飞鱼酱① 提交于 2020-01-04 06:20:33

问题


this is my code at index.html

<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
    <script src="javascript/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script src="javascript/i18next-1.7.4.js" type="text/javascript"></script>

    <title>i18next test</title>
</head>

<body>
    <p id="id001" data-i18n="first_data">first</p>
</body>

<script type="text/javascript">

$(document).ready(function(){
  language_complete = navigator.language.split("-");
  language = (language_complete[0]);

  i18n.init({
  lng: language, 
  resGetPath: 'locales/__lng__.json',
  fallbackLng: "en",
  }, function(){
    $("first_data").i18n();
  });

});
</script>

</html>

And I've created 2 json file at the same directory with index.html

locales/en.json
locales/de.json

json file content:

{
    "first_data": "de-first-data"
}

Firefox try to load de.json and en.json but get the error 404.

Do you have any idea why i18next cannot load the json file.

This is my folder structure below:

index.html
locales/de.json
locales/en.json
javascript/i18next-1.7.4.js
javascript/jquery-1.11.1.min.js

回答1:


You host application in IIS. IIS by default (as far as I know) doesn't support JSON file type.

Following question is related to same problem: ERROR 404.3 Not Found for JSON file




回答2:


Have you tried with ?

resGetPath: 'javascript/locales/__lng__.json',


来源:https://stackoverflow.com/questions/27171653/i18next-load-json-error404-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!