In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to solve Ajaxrequestresponse garbled, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
The strange thing is that there is a problem today.
The code is as follows:
AjaxRequestObj.createEqStatusParameter=function () {if (eqStatusArray.length < 1) {return;} var paramNameArray = new Array (); var paramValueArray = new Array (); / / take the status 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) } / / decompose and generate the request string. 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)
The client passes the parameter to the application side in UTF-8 mode, and when using this parameter, it can be taken directly from the request.
[Ajax receives response message]
Directly use forward jump to implement local content changes in div
The code is as follows:
If ("doQueryRequest" .equals (actParam)) {EquipUtils equipUtilsObj = EquipUtils.getInstance (); / / query parameters, stitching equipStatusMgrObj.setEquipCondition (equipUtilsObj.createEquipFilter (request)); equipStatusMgrObj.setEquipStatusCondition (equipUtilsObj.getEquipStatusDate (request)); / / device information List equipArray = equipStatusMgrObj.queryEquip (null); / / device status Map 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);} catch (Exception e) {e.printStackTrace () }} else if ("getPageToolBar" .equals (actParam)) {PaginationEntity pEntity = (PaginationEntity) sessionObj.getAttribute ("paginationEntity"); String tempStr = pEntity.getPaginationTool (); OutputStream out; try {response.setContentType ("text/html;charset=UTF-8"); out = response.getOutputStream (); out.write (tempStr.getBytes ("UTF-8")); out.flush (); out.close () } catch (IOException e) {e.printStackTrace ();}}
Because, currently using xmlHttpObj.responseText,responseText is UTF-8 by default, it is a good choice to turn the page that you jump to into UTF-8. At least don't worry about garbled code.
[reason for garbled code]
Previously, this feature used GB18030 coding, which was normal on other clients and colleagues' machines until it was modified, but there was garbled code on my own machine. When I use UTF-8 to unify the rendering files used for this function, I ok, and I don't know which xmlHttpObj touched the nerve of the machine. Checked some information is also about the trend of internationalization, the problem is solved, but the reason has not been found!
[found a Bug]
Response.setContentType ("text/html;charset=UTF8"); do not make mistakes on my machine, but on my colleagues' machines
Change to response.setContentType ("text/html;charset=UTF-8"); everything OK
This is the end of the answer on how to solve the Ajaxrequestresponse garbled problem. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.