


Solutions to common problems in JavaScript (garbled characters, IE cache, proxy)_javascript skills
Two commonly used methods to solve AJAX Chinese garbled characters
1. EncodeURI on the client side (utf-8 does not need to be done, the default), and convert iso-8859-1 encoding to utf-8 encoding on the server side
2. EncodeURI twice on the client side and convert it once on the server side.
The reason why the second method can solve the problem:
After two conversions, perform the first decoding in the first getparameter method. Because the solution is in English (the result after the first encode), there will be no problem; the second time using URLDecoder decode method, so this problem can be solved normally. It should be noted that the decoding format needs to be specified as "utf-8" in the decode method. Many Chinese platforms do not use utf-8 (I guess it is gb2312), so the default conversion of decode is not necessarily utf-8.
The reason why the client is encoded twice and decoded only once on the server is because of Tomcat. In order to make programming convenient for programmers (get and post use the same code), Tomcat will automatically decode the encoding of the post, so there is one less handwritten decoding statement on the server side. The reason why we need to perform encoding and decoding again is because the automatic decoding operation of Tomcat is not necessarily decoded according to the encoding we want, but the codes decoded for English and other characters are the same no matter what platform they are on, so it can be Tomcat automatically interprets the result of the first encoding, and then manually interprets the encodeURI code once to obtain the format you need.
Additional: Now I have observed the behavior of the browser again, and I feel that it is not the fault of Tomcat, because the Chinese displayed in the browser is not the encoded content. I am now confused about these encoding issues. I'm confused, I hope friends who know this knowledge can give me some advice!
Solving the IE cache problem
Add a timestamp and want to check it?
Solve the agency problem
Want to do this? Convert to $
Sample code:
function verify() {
//Method 1 to solve the Chinese garbled problem, the data sent from the page side is encoded as an encodeURI, and the server segment uses new String(old.getBytes("iso8859-1"), "UTF-8");
// Method 2 to solve the problem of Chinese garbled characters. The data sent from the page side is encoded twice as encodeURI. In the server segment, use URLDecoder.decode(old,"UTF-8")
var url = "AJAXServer?name=" encodeURI(encodeURI($ ("#userName").val()));
url = convertURL(url);
$.get(url,null,function(data){
$("#result"). html(data);
});
}
//Add a timestamp to the url address, fool the browser and not read the cache
function convertURL(url) {
// Get the timestamp
var timstamp = (new Date()).valueOf();
//Splice the timestamp information into the url
//url = "AJAXServer"
if (url. indexOf("?") >= 0) {
url = url "&t=" timstamp;
} else {
url = url "?t=" timstamp;
}
return url;
}

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

DNS (DomainNameSystem) is a system used on the Internet to convert domain names into corresponding IP addresses. In Linux systems, DNS caching is a mechanism that stores the mapping relationship between domain names and IP addresses locally, which can increase the speed of domain name resolution and reduce the burden on the DNS server. DNS caching allows the system to quickly retrieve the IP address when subsequently accessing the same domain name without having to issue a query request to the DNS server each time, thereby improving network performance and efficiency. This article will discuss with you how to view and refresh the DNS cache on Linux, as well as related details and sample code. Importance of DNS Caching In Linux systems, DNS caching plays a key role. its existence

Title: Methods and code examples to solve the problem of garbled characters when importing Chinese data into Oracle. When importing Chinese data into Oracle database, garbled characters often appear. This may be due to incorrect database character set settings or encoding conversion problems during the import process. . In order to solve this problem, we can take some methods to ensure that the imported Chinese data can be displayed correctly. The following are some solutions and specific code examples: 1. Check the database character set settings In the Oracle database, the character set settings are

Tips for dealing with garbled Chinese file names in PHP During the development process, we often encounter the problem of garbled Chinese file names, especially when processing files uploaded by users. In PHP, how to correctly handle garbled file names is a common and important problem. This article will introduce some techniques for dealing with garbled Chinese file names and provide specific code examples to help readers better deal with this challenge. Problem description: When users upload files, the Chinese file names sometimes appear to be garbled. This is because different operating systems and browsers

How to deal with the problem of garbled characters in the Linux terminal. When using the Linux system, sometimes the text displayed in the terminal will be garbled. This brings inconvenience to us when using the terminal and needs to be dealt with in time. This article will introduce how to deal with some common Linux terminal garbled problems, and provide specific code examples. Problem 1: Garbled Chinese characters on the terminal. Garbled Chinese characters on the terminal are usually caused by incorrect character encoding settings on the terminal. We can solve this problem by modifying the terminal's character encoding settings. #View the current terminal

Win11 is Microsoft's latest operating system, but some users may encounter the problem of displaying garbled characters when booting, which will affect the normal use of the system. This article will introduce some methods to solve this problem. Method 1: 1. Press the [Win+S] key combination, or click the [Search icon] next to the start icon on the taskbar. In the opened Windows search, enter [Control Panel] in the search box, and then click [Open]. The best matching control panel application out of the control panel window; 2. In the control panel window, switch to the [Category] view mode, and then click [Clock and Zone-Region]; 3. In the zone window, switch to the [Management] tab, and then click [Change] System Regional Settings]; 4. [Uncheck] Beta version: Use Unicode

Strategies and techniques for solving Chinese garbled characters in Oracle database. In actual database applications, many developers or administrators may encounter the problem of Chinese garbled characters in Oracle database. When the data in the database is garbled, it not only affects the correctness and readability of the data, but also brings many problems to the system. This article will combine specific code examples to introduce the strategies and techniques for solving Chinese garbled characters in Oracle database to help readers better understand and solve this problem. 1. The reason for garbled characters is inconsistent character sets: database connection and application

PHPAPCu (replacement of php cache) is an opcode cache and data cache module that accelerates PHP applications. Understanding its advanced features is crucial to utilizing its full potential. 1. Batch operation: APCu provides a batch operation method that can process a large number of key-value pairs at the same time. This is useful for large-scale cache clearing or updates. //Get cache keys in batches $values=apcu_fetch(["key1","key2","key3"]); //Clear cache keys in batches apcu_delete(["key1","key2","key3"]);2 .Set cache expiration time: APCu allows you to set an expiration time for cache items so that they automatically expire after a specified time.

There is a close interaction between the CPU (central processing unit), memory (random access memory), and cache, which together form a critical component of a computer system. The coordination between them ensures the normal operation and efficient performance of the computer. As the brain of the computer, the CPU is responsible for executing various instructions and data processing; the memory is used to temporarily store data and programs, providing fast read and write access speeds; and the cache plays a buffering role, speeding up data access speed and improving The computer's CPU is the core component of the computer and is responsible for executing various instructions, arithmetic operations, and logical operations. It is called the "brain" of the computer and plays an important role in processing data and performing tasks. Memory is an important storage device in a computer.
