【问题标题】:JQgrid: Russian data is displayed as Junk/invalid symbolsJQgrid:俄罗斯数据显示为垃圾/无效符号
【发布时间】:2014-07-24 20:20:28
【问题描述】:

我有一个 jqgrid,我可以在其中上传英语/法语/俄语的数据。当我上传俄语字符时,它显示为一些无效符号。像……??? ?? 我把jsp页面的编码改成了<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

在 jq 配置中有什么具体要更改的吗?请帮忙。 以下是我的 Jquery 实现

jQuery('#studentLst')
            .jqGrid(
                    {
                        url : endpoint,
                        datatype : 'json',
                        rownumbers : true,
                        height : 250,
                        colNames : [ 'StudentID', 'Name', 'Marks','Description' ],
                        colModel : [ {
                            name : 'sId',
                            index : 'sId',
                            hidden : true
                        }, {
                            name : 'name',
                            index : 'name',

                        }, {
                            name : 'marks',
                            index : 'marks',
                            width : 200

                        },{
                            name : 'description',
                            index : 'description',
                            width : 190,
                            sortable : false
                        }],
                        multiselect : false,
                        rowNum : 10,
                        rowList : [ 10, 20, 40, 60, 80, 100 ],
                        viewrecords : true,
                        autowidth : true,
                        caption : 'Student List',
                        onSelectRow : function(ids) {
                            //Load sub grids
                        },

                        gridComplete : function() {
                            //Implementation
                        },
                        loadComplete : function(response) {

                        },
                        onPaging : function(pgButton) {
                            $("#studentLst").setGridParam({
                                datatype : 'json'
                            });
                        },
                        pager : "#studentLstPg"
                    });
jQuery('#studentLst').navGrid('#studentLstPg', {
        search : false,
        addfunc : function() {
            //add student
        },
        addtitle : 'Add Student',
        editfunc : function() {
            //update student info implementation
        },
        edittitle : 'Edit Student',
        delfunc : function() {
            // Show confirmation box and delete the student

        },
        deltitle : "Delete Student"
    });
    var grid = jQuery("#studentLst");
};

【问题讨论】:

  • 您是否真的以UTF-8 格式保存文件(html/jsp 页面)?
  • @Oleg 我在网格中加载的动态数据是多语言的。
  • 很明显,您动态加载数据,您必须发布更多实现细节。如果你能正确地做所有事情,你就不会有问题。因此,需要查看更多实现细节来找出您犯了哪些错误。尝试在 html/jsp 页面上直接包含一些俄语文本,并验证您是否有同样的问题。例如,您的数据库或访问数据库的方式可能存在问题。
  • @Oleg 我已经更新了 jquery 实现。
  • 您是否将俄语文本直接放在 jqGrid 之外的 html/jsp 页面(如<span>Привет!</span>)上?你看对了文字吗?从url : endpoint 返回的data 有问题吗?您是否验证了Fiddler 或开发者工具(按 F12 启动,然后在网络选项卡中启动跟踪)从服务器返回的数据是正确的?

标签: javascript jquery jqgrid


【解决方案1】:

动态文件编码

如果数据是从动态 json 或 xml 加载的,则在返回之前,您应该在该文件中包含一个标头,在其中指示字符集。在 jsp 中会是:

<%@ page language="java" contentType="application/json; charset=UTF-8"
    pageEncoding="UTF-8"%>

看这里:

Set Content-Type to application/json in jsp file

在 php 中是:

header('Content-Type: text/html; charset=utf-8');

静态文件编码

如果它是静态文件,请验证您是否使用正确的编码保存它(例如,如果您看不到文件的编码,请尝试使用 notepad++ / sublime text,这种应用程序可以选择使用以下方式保存文件不同的编码)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多