Home  >  Article  >  Backend Development  >  How to solve the Chinese garbled problem in php ie get

How to solve the Chinese garbled problem in php ie get

藏色散人
藏色散人Original
2020-09-03 09:25:591626browse

php ie get Chinese garbled solution: first open the corresponding PHP code file; then use the "encodeURI" statement to convert Chinese to URI encoding to solve the garbled problem.

How to solve the Chinese garbled problem in php ie get

Recommended: "PHP Video Tutorial"

php ie get Chinese garbled solution:

1. Solving the problem of Chinese garbled characters in the get method URL under IE

I recently encountered a problem when working on a project. Under Chrome, when using the ajax get method to request data , there is no problem with Chinese characters in the URL, but under IE, the Chinese characters will be turned into garbled characters and sent over, making it impossible to obtain the data.

At first I thought of letting the server parse it to solve the problem, but since it was already garbled when sent, the server could not parse the garbled code.

2. Later I thought of a way: use the encodeURI method to convert Chinese to URI encoding, which can perfectly solve the problem of garbled characters and is compatible with all browsers.

The specific code is as follows:

var url = encodeURI("http://xxx.xxx.xxx.23?" + 中文);
 
$.ajax({
 
    type:"get",
 
    url:url,
 
    dataType:"json",
 
    success:function(data){
 
        console.log(data)
 
    },
 
    error:function(err){
 
        console.log(err)
 
    }
 
});

The above is the detailed content of How to solve the Chinese garbled problem in php ie get. 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