Home  >  Article  >  Web Front-end  >  How to solve the problem of sending ajax garbled characters

How to solve the problem of sending ajax garbled characters

藏色散人
藏色散人Original
2021-12-17 15:28:562882browse

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.

How to solve the problem of sending ajax garbled characters

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


  encodingFilter
  org.springframework.web.filter.CharacterEncodingFilter
  
    encoding
    utf-8
  
  
    forceEncoding
    true
  


  encodingFilter
  /*

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

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Why can't ajax go back?Next article:Why can't ajax go back?