Solution to garbled ajax page and garbled get post_PHP tutorial
Solution to garbled ajax page and get post garbled code
In the past, ASP pages had various garbled characters. When the page was refreshed, the codes were garbled or the links were garbled. Last night, I asked my mother-in-law, and she came up with a solution. Add , 65001 refers to the UTF-8 encoding format GB2312 is 936, the reason is that other programs did not declare Response.CodePage when you entered the UTF-8 page. Session.CodePage is assigned a value immediately (65001 or 936 is assigned a different value depending on the version), and then when entering another page, the Response.CodePage of the other page is immediately assigned a value by Session.CodePage. So if that page gets @ CODEPAGE = 936 If the Response.CodePage of your page is assigned a value of 65001, it will definitely be garbled, so write the code uniformly at the beginning of the page.
Then last night, I encountered another problem. When AJAX returned to Chinese, it displayed garbled characters. The encoding of the two pages was the same UTF-8. Why did garbled characters appear? I checked Du Niang and said that in the AJAX processing page, add The result page does not display the content. I have studied it and it is probably a data encoding problem in the database tutorial, because the ACCESS data encoding is based on the encoding when you write the data. I wrote it in. When it was GB2312, now using UTF-8 format encoding and decoding will definitely cause garbled characters. What should I do if I set and then AJAX Chinese will return to normal. Here is the explanation of the Charset attribute in W3C It appends the character set name to the content-type header of the page's Response object.
Add
Page output display
I guess Charset changed the character set to GB2312 so it can accept GB2312 encoded data so it won’t be garbled
Take a look at the ajax solution to get and post garbled characters
There are two types of garbled data in terms of program execution. One is that the Chinese text sent to the background program itself is garbled, because xmlHTTP follows the word processing mechanism of web page special effects and uses UTF-8 encoding. But if the background page uses GB2312 or other types of encoding, the received data will naturally be garbled. Another problem is that when data is received and returned, characters are garbled. This is also caused by the difference between the encoding used by the background page and the Javascript encoding. The characters returned by the server script will use the server encoding such as GB2312 by default. The problem of garbled data sent back by the server is easy to solve. We only need to add a file header that defines the encoding on the page where the data is sent back by the server.
When defining file header information, depending on the script, you can use the following methods:
PHP:header("Content-Type:text/html;charset=GB2312");
ASP:Response.Charset("GB2312")
JSP:response.setHeader("Charset","GB2312");
(Other scripts can search for their related class libraries, and usually have functions or methods for setting header information.)
After talking about sending back messages, let’s talk about the problem of sending garbled messages. In fact, regardless of the encoding, the Chinese characters we input will be sent to the server correctly in UTF-8 format. However, when the server receives it, it is not decoded in the way we expected, but uses the server's default characters. Encoding method, usually GB2312 to decode information. Then the characters we see are naturally wrong.
We all know that XMLHTTP has two ways of sending data, one is GET and the other is POST. The garbled code of GET is relatively simple to solve. Just add a header information that defines the encoding: setrequestheader("Content-Type", "text/html; encoding=gb2312"). In this way, the data sent by GET method will be correctly understood by the server script as GB2312 method and decoded.
The more difficult part is when using the POST method to send data, the above method is invalid because the Content-type used by the POST data is: xmlObj.setrequestheader("Content-Type","application/x-www-form -urlencoded"); No character encoding is defined. I have encountered great difficulties in solving this problem, but I have found two better solutions so far. The first is to URL-encode the Chinese characters before sending them to the server. That is, use: encodeURI().
But it should be noted that this method needs to be used twice. The first time is to process the characters into URL encoding. The second time is to encode the encoded data again. This is done because if the encoding is sent for the first time, the server will automatically decode it. If so, we have no way to control the decoding method we want. So encodeURL needs to be performed twice. The purpose of this is that the data we obtain on the server side is a string after encodedURL. Then we use the corresponding decoding function of the server-side script to restore the string. In this way, we get the correct string we want. The disadvantage of this is that we have to exponentially increase the amount of data sent. You know, as the amount of data increases, the chance of errors increases.
Another way is to use cookies to dump data, which does not increase the data but requires certain browser permissions. Although reading and writing cookies is very easy. But I think this operation is not ideal. I can't say much without testing it. And I think there should be a third way to solve the problem of garbled characters.
Solution to AJAX POST garbled characters in PHP!
Although it is not advanced or handsome, it finally solved the problem. The solution to the problem is officially due to PHP's complete function library! Just one iconv() function solves the problem of garbled characters!
On the client side, no settings are required. Just get the normal value and send it to the server side using xmlHTTP and then accept the value normally on the server side. Just use the iconv() function to re-encode the string after receiving the value!
$R_Guest = strval(iconv("UTF-8","GB2312",$_POST["R_Guest"]));
$R_Content = strval(iconv("UTF-8","GB2312",$_POST["R_Content"]));

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

Fibers was introduced in PHP8.1, improving concurrent processing capabilities. 1) Fibers is a lightweight concurrency model similar to coroutines. 2) They allow developers to manually control the execution flow of tasks and are suitable for handling I/O-intensive tasks. 3) Using Fibers can write more efficient and responsive code.

The PHP community provides rich resources and support to help developers grow. 1) Resources include official documentation, tutorials, blogs and open source projects such as Laravel and Symfony. 2) Support can be obtained through StackOverflow, Reddit and Slack channels. 3) Development trends can be learned by following RFC. 4) Integration into the community can be achieved through active participation, contribution to code and learning sharing.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment