我使用jquery进行ajax验证,在action里面返回一个JSONObject对象。代码如下:
List temp = packageService.queryCardBySeq(cardseq);
JSONObject jsonObj = new JSONObject();
if(temp!=null&&temp.size()>0){
Card card = (Card)temp.get(0);
jsonObj.accumulate("id", card.getId());
jsonObj.accumulate("card_code", card.getCard_code());
jsonObj.accumulate("card_name", card.getCard_name());
jsonObj.accumulate("card_seq", card.getCard_seq());
jsonObj.accumulate("card_value", card.getCard_value());
jsonObj.accumulate("tel_no", card.getTel_no());
out.print(jsonObj);
}
页面上取msg.card_name时乱码,其他都正确(其他不含中文只有card_name含中文)。搞了一早上还是没能解决。该用的方法都用了。
response设置为utf-8,页面设置成utf-8,容器设成utf-8全都试过了还不行。有没有谁知道如何解决。尽量说点有实际作用的。对了下面是jsp请求
[code=JavaScript]
$.ajax({url: "${home}/sales/packagemg.do?cmd=checkCardIsAxist",
type:"post",
dataType:"json",
cache:false,
data:"cardseq="+obj.value,
success:function(msg){
if(msg==0){//返回的是0的话代表该串号不存在所以不能打包
alert("该卡不能打包!");
tempTd[0].children[0].value="";
tempTd[0].children[1].value="";
tempTd[2].children[0].value="";
tempTd[3].children[0].value="";
tempTd[4].children[0].value="";
obj.focus();
}else{//否则的话代表串号存在,则把返回的对象的各个属性加载到文本框中
tempTd[0].children[0].value=msg.card_code;
tempTd[0].children[1].value=msg.id;
tempTd[1].children[0].value=msg.card_seq;
tempTd[2].children[0].value=msg.tel_no;
tempTd[3].children[0].value=msg.card_name;
tempTd[4].children[0].value=msg.card_value;
}
}
});
[/code]