Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve Ajaxrequestresponse garbled

Shulou Source: shulou.com Published: 2022-06-03 14:13:33 10月06日 Update

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.

Tags: Garbled machine problem UTF-8 parameter code information content function reason colleague customer that is more status device help answer good easy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology Shulou Information Huawei OPPO Reno