您好,我的数据库中有电子邮件地址,例如“abc@yahoo.co.in”,当我检索它时,在将该对象返回给客户端之前,我在 Controller 上也得到了相同的地址,但是当我在我的 Controller 上提醒该值时java 脚本页面,“@”正在转换为一些随机字符并且无法正确显示。我该如何解决这个问题?
服务器代码:
enter code here
public AppUser findById(@FormParam("employeeId") String eId ){
int id=Integer.parseInt(eId);
AppUser appUser=null;
appUser= evaluatorService.findById(id);
return appUser;
}
在调试 appUser 时,它为我提供了正确的数据。
我的客户端代码:
$.ajax({
type : 'GET',
url : 'rest/evaluator/fetchEvaluatorById',
data : {
'employeeId' : employeeId
},
success : function(data) {
$('#evaluatorDetailEdit').dialog({
width: 400,
height: 400,
});
alert(data.email);
$('#employeeId').val(data.employeeId);
$('#name').val(data.name);
$('#lastName').val(data.lastName);
$('#email').val(data.email);
}
});
最佳答案
有一些 hacky jquery-workaround - 也许有更好的解决方案,但这应该有效:
var original = "@";
alert("Original: " + original);
// Hacky jquery-workaround:
// 1. pasting encoded text as html in a "virtual" textarea and
// 2. get the decoded text:
var decoded = $('<textarea/>').html(original).text();
alert("Decoded: " + decoded);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
关于javascript - json将字符转换为随机字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28831753/