Get the App
SLTechnology News&Howtos  ›  Development  › 

What if the Chinese garbled code occurs when ajax returns json in JQuery

Shulou Source: shulou.com Published: 2022-06-03 18:01:32 11月13日 Update

The purpose of this article is to share with you about what to do when Chinese garbled occurs when ajax returns json in JQuery. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Return json with jQuery ajax call, Chinese garbled problem

The Js code is as follows:

$.ajax ({url:'/ test/testAction.do?method=test', type: 'POST', dataType:' json', timeout: 5000, async: false, error: function () {alert ('failed to get data!') ;, success: function (json) {jsObject = eval (json);}}); return jsObject

Js code

$.ajax ({url:'/ test/testAction.do?method=test', type: 'POST', dataType:' json', timeout: 5000, async: false, error: function () {alert ('failed to get data!') ;}, success: function (json) {jsObject = eval (json);}); return jsObject; action:

Java code

JSONArray json = JSONArray.fromObject (SysList); / / SysList is a List / / set response ContentType to solve Chinese garbled response.setContentType ("text/html;charset=UTF-8"); response.getWriter () .print (json.toString ()); return null; Java code JSONArray json = JSONArray.fromObject (SysList); / / SysList is a List / / set response ContentType to solve Chinese garbled response.setContentType ("text/html;charset=UTF-8") Response.getWriter (). Print (json.toString ()); return null; thank you for reading! This is the end of the article on "what to do when the Chinese garbled code occurs when ajax returns json in JQuery". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Garbled Chinese code how to do time out content data more articles good practical articles see knowledge questions references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS Shulou Technology Microsoft Shulou Information