Home >Web Front-end >JS Tutorial >Solution to the problem of garbled page form data in different encodings_javascript skills

Solution to the problem of garbled page form data in different encodings_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:13:551008browse

I encountered a very magical problem today. A user told me that the form on the website here does not get a return value after it is submitted to the query system. The query result is 0 records, but the results of the local pure HTML execution can be searched. to the value. I verified it myself and found that it was indeed the case, and compared the parameters submitted by GET on both sides. Except for the value of one field that was different, the number of parameters was the same, so it was considered that it might be caused by encoding issues.

After opening the two files respectively, I found that the encoding on the two sides was indeed inconsistent, and the server side was GB2312. The parameters passed UTF-8 encoding could not be parsed normally in the past, so I searched and found a rarely used one on the form. properties.

Copy code The code is as follows:

accept-charset=”gb2312″

This attribute is very interesting. You can set the encoding in which the form will encode the content. So, just add this attribute to the form.

But it’s disgusting. IE does not support this attribute, so I had to hack the onSubmit() method of the form and add

Copy code The code is as follows:

onsubmit=”document.charset=’gb2312′;”

The problem is completely solved.
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