1.中文通过url进行页面传递出现乱码。
例子:
checkResource:function()
{
var group=encodeURI(encodeURI($("#group").val()));
var customName=encodeURI(encodeURI($("#customName").val()));
var resName=encodeURI(encodeURI($("#resName").val()));
var ip=encodeURI(encodeURI($("#ip").val()));
$("#content").load("jsp/resource/resourceList.jsp?resName="+resName+"&group="+group+"&ip="+ip+"&customName="+customName,function(){
$.deviceResource.showDeviceByConditiontwo();
});
}
页面通过${param.resName} 对于中文将不会是乱码。
2.测试常用需要将json对象转字符串。字符串转json。
对象转字符串:常用的场景是通过异步请求数据返回时需要对对象数据进行分析,此时可用。
var a = {a:1,b:2}
JSON.stringify(a)
结果:
"{"a":1,"b":2}"
var str = '{"name":"huangxiaojian","age":"23"}'
JSON.parse(str)