Ajax request response 乱码解决方法
2024-09-01 08:29:29
供稿:网友
此功能已进入试用一周了,都没有问题,奇怪的是今天出现了问题??
代码如下:
AjaxRequestObj.createEqStatusParameter=function() {
if (eqStatusArray.length < 1) {
return;
}
var paramNameArray = new Array();
var paramValueArray = new Array();
//取状态数组
for (var index = 0, step = eqStatusArray.length; index < step; index++) {
var tempEqStatusObj = eqStatusArray[index];
paramNameArray.push(tempEqStatusObj.eqCode + "`" + tempEqStatusObj.opDateTime);
paramValueArray.push(tempEqStatusObj.status);
}
//分解、生成请求串。
var paramStr = "";
paramStr = paramStr.concat("eqStatusNames=").concat(encodeURIComponent(paramNameArray.join(","))).concat("&");
paramStr = paramStr.concat("eqStatusValues=").concat(encodeURIComponent(paramValueArray.join("`")));
return paramStr;
};
xmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
xmlHttpObj.send(param);
客户端将参数以UTF-8方式传递给应用端,在使用此参数时直接从request中取就可以。
[Ajax接收响应信息]
直接使用forward跳转实现div局部内容变更
代码如下:
if ("doQueryRequest".equals(actParam)) {
EquipUtils equipUtilsObj = EquipUtils.getInstance();
//取查询参数、拼接
equipStatusMgrObj.setEquipCondition(equipUtilsObj.createEquipFilter(request));
equipStatusMgrObj.setEquipStatusCondition(equipUtilsObj.getEquipStatusDate(request));
//设备信息
List<DynaBean> equipArray = equipStatusMgrObj.queryEquip(null);
//设备状态
Map<String, Map<String, String>> equipStatusMapping =
equipStatusMgrObj.queryEquipState4Map(equipArray, null);
sessionObj.setAttribute("paginationEntity", equipStatusMgrObj.getPaginationEntity());
sessionObj.setAttribute("equipCondition", equipStatusMgrObj.getEquipCondition());
sessionObj.setAttribute("eqStatusCondition", equipStatusMgrObj.getEquipStatusCondition());
request.setAttribute("equipList", equipArray);
request.setAttribute("dateList", equipStatusMapping);
try {
request.getRequestDispatcher("/eq/detectPoint/InnerEqStatusRefresh.jsp").forward(request, response);