多语言功能在资源文件的正常 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
使用以下任何函数解码 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('Éxito')
output: "Éxito"
关于javascript - 如何从资源文件中解决西类牙重音问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58619102/