【问题标题】:How to fix spanish grave accent issue from resouce file?如何解决资源文件中的西班牙重音问题?
【发布时间】:2019-10-30 05:09:17
【问题描述】:

多语言功能在资源文件的普通 html 页面中运行良好,但在涉及 javascript 时它会失败例如: 成功是在 html 页面中的西班牙语中的“éxito”,它工作正常,但是当涉及到 javascript 时,它显示为 & #201;xito
如果我们在 javascript 中将 'éxito' 硬编码为字符串,它也可以工作,但是当从资源文件加载到 javascript 时它会失败

                   

function Login_Create_user(id) {

        $.ajax({
            url: '@Url.Action("CreateLogin", "User")',
            type: "POST",
            async: false,
            data: { studentId: Id },
            success: function(result1) {
                if (result1 == true) {
                    swal("@Resource.Success", "StudentLoginCreatedSuccessfully.", "success");
                    window.location.reload();
                } else if (result1 == false) {
                    swal("@Resource.warning", "@Resource.FailedtoCreatelogin ! @Resource.Pleasetryagainlater", "warning");
                } else {

                    swal("@Resource.warning", result1, "warning");
                }
            },
            error: function(ex) {

            }
        });
    }

我希望“éxito”从资源文件加载到 javascript 时应该加载为“éxito”

【问题讨论】:

标签: javascript jquery asp.net-mvc resx


【解决方案1】:

您可以使用纯 JavaScriptJquery 使用以下任何函数来解码 ajax 响应

//Decode HTML-entities (JS)
function decodeHTMLEntities(text) {
  var textArea = document.createElement('textarea');
  textArea.innerHTML = text;
  return textArea.value;
}

//Decode HTML-entities (JQuery)
function decodeHTMLEntities(text) {
  return $("<textarea/>")
    .html(text)
    .text();
}


decodeHTMLEntities('&#201;xito')

输出:“Éxito”

【讨论】:

    猜你喜欢
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    • 1970-01-01
    • 2015-01-16
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多