javascript - 如何解决资源文件中的西班牙重音问题?
问题描述
多语言功能在资源文件的普通 html 页面中运行良好,但是当涉及到 javascript 时,它会失败 例如:在 html 页面中,成功是西班牙语中的“éxito”,它工作正常,但在涉及到 javascript 时,它显示为 201;xito
如果我们将 'éxito' 硬编码为 javascript 中的字符串,它也可以工作,但是当从资源文件加载到 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”
解决方案
您可以使用以下任何函数来解码 ajax 响应,或者使用 pureJavaScript
或Jquery
//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('Éxito')
输出:“exito”
推荐阅读
- java - 在apache camel spring dsl xml中调用两个toD
- awk - 使用awk,如何平均文本文件中两个字符串之间的列中的数字
- javascript - 使用 javascript 在文本框中创建分数
- python - 比较列表中的跨度,如果相似则返回标签
- typescript - 如何使用 TS API 检查不在“rootDir”下?
- excel - VBA遍历目录中的文件,在另一个目录中另存为csv,如果文件存在则跳过
- azure - 在 Azure Devops Pipelines 中的部署作业生命周期挂钩之间共享变量
- rest - MS Graph API - 创建在线会议,不使用拨入/会议信息生成
- c# - 如何在 C# 中打印 \"
- sql - SQL Server - 组和数字匹配连续值