Home > Article > Web Front-end > How to solve jquery serialize garbled code?
The reason why jquery serialize Chinese garbled characters: [serialize()] automatically calls the encodeURIComponent method to encode the data; solution: call "decodeURIComponent(XXX,true);" to decode the data.
Related recommendations: "jQuery Video Tutorial"
The operating environment of this tutorial: windows7 system, jquery3.5 version , this method is suitable for all brands of computers.
After using the jquery serialize method in the project, I found that the Chinese encoding format had been converted. I thought it would be solved by directly setting tomcat to utf-8. I found that this was not the case, and later went online directly. After searching Google, I got the following answer: The special record is as follows (it works after trying it)
1:
Reason: .serialize()
is called automatically Use the encodeURIComponent method to encode the data.
Solution: Call decodeURIComponent(XXX,true); to decode the data.
For example:
var params = jQuery("#formId").serialize(); // http request parameters. params = decodeURIComponent(params,true);
Two:
1. Replace encodeURIComponent in the jquery.js file with encodeURI. It can solve Chinese garbled characters. (I don’t know where to change it, I haven’t tried it yet)
2. Another way is to set the character set of all jsp and xml to UTF-8. (Both of my files are originally UTF-8, I guess there are some missing ones, whether it is feasible is unknown)
JSP
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
XML
<?xml version="1.0" encoding="UTF-8"?>
More programming related For knowledge, please visit: programming video course! !
The above is the detailed content of How to solve jquery serialize garbled code?. For more information, please follow other related articles on the PHP Chinese website!