访问JavaScript和HTML应用程序中的JSON文件

时间:2020-12-05 16:04:34

I want to implement i18n in my application, which is written in HTML and JavaScript, with PHP as the backend. I have a JSON file, with all the keys and translations. Since I've read that JSON files cannot be read from local storage, where would I store these JSON files, on XAMPP, so I can access them in my app? Also, can I directly access them using JavaScript, or would I need to use PHP?

我想在我的应用程序中实现i18n,它是用HTML和JavaScript编写的,用PHP作为后端。我有一个JSON文件,包含所有键和翻译。既然我已经读过JSON文件无法从本地存储中读取,我会在XAMPP上存储这些JSON文件,所以我可以在我的应用程序中访问它们?另外,我可以使用JavaScript直接访问它们,还是需要使用PHP?

Thank you

1 个解决方案

#1


0  

this is using jQuery

这是使用jQuery

$.ajax({
        url: url +"//jsonfile.txt",
        dataType: 'text',
        success: function (data, status) {
            var jsonObject = JSON.parse(data);
            jsondata = jsonObject;
        },
        error: function () {

        }
    });

#1


0  

this is using jQuery

这是使用jQuery

$.ajax({
        url: url +"//jsonfile.txt",
        dataType: 'text',
        success: function (data, status) {
            var jsonObject = JSON.parse(data);
            jsondata = jsonObject;
        },
        error: function () {

        }
    });