Home  >  Article  >  Web Front-end  >  What to do if ajax submitted data is garbled in jquery

What to do if ajax submitted data is garbled in jquery

coldplay.xixi
coldplay.xixiOriginal
2020-12-07 10:32:271925browse

Solution to the garbled data submitted by ajax in jquery: 1. Set the project encoding to [utf-8]; 2. Set the encoding of each interface to [utf-8]; 3. Write an Encode encoding filter , to ensure the consistency of each request response encoding; 4. Add the encoding method to [$.ajax()].

What to do if ajax submitted data is garbled in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1&&ajax2.0 version, Dell G3 computer. This method is suitable for all brands of computers.

Solution to garbled data submitted by ajax in jquery:

I can only say that the garbled problem is a very troublesome problem. My project is encoded with GBK. Now I use When I went to jQuery-Ajax, I found that the submitted data was garbled in Chinese. I tried many methods online but to no avail. Finally, I recoded the project to UTF-8 and the problem was solved.

My suggested solution here:

①Set the project encoding to utf-8.

②The encoding of each interface is set to utf-8.

③Write an Encode encoding filter to ensure the consistency of each request response encoding.

④Add encoding method to $.ajax().

contentType:"application/x-www-form-urlencoded;charset=utf-8",

Reason:

requestHeadersContent-Type of the browser are all utf-8 encoded, because jquery ajax also uses utf-8 Support for Chinese to encode sending data.

In short, I deeply feel the fear of being dominated by utf-8.

Related learning recommendations: javascript learning tutorial

The above is the detailed content of What to do if ajax submitted data is garbled in jquery. 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