Home >Web Front-end >Front-end Q&A >How to solve the problem of sending ajax garbled characters
Solution to sending ajax garbled characters: 1. Check whether the character interceptor is configured in web.xml; 2. Modify the jsp page to utf-8; 3. Change the ajax request to a post request.
The operating environment of this article: Windows 7 system, jquery version 3.2.1, Dell G3 computer.
How to solve the problem of sending ajax garbled characters?
Solution to the problem of Chinese garbled characters when JQuery sends an ajax request:
Troubleshoot the project first:
1. Whether it is configured in web.xml Character interceptor
<filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
2. Is the jsp page utf-8
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
By the way, I also add this tag and send utf-8 uniformly, but I heard it is a bit tasteless
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8″ />
3. After troubleshooting, change the ajax request to a post request
$.ajax({ url:"list", type:'post', data:{ param:recode, city:locationActive }, dataType: 'json',//要求服务器返回的是json success:function(res){}
Recommended learning: "ajax video tutorial"
The above is the detailed content of How to solve the problem of sending ajax garbled characters. For more information, please follow other related articles on the PHP Chinese website!