JS Ajax encodeuricomponent code PHP mysql garbled problem

Source: Internet
Author: User

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<TITLE>JS Ajax encodeuricomponent coded PHP tutorial MySQL tutorial garbled problem </title>

<body>

var url = "Post.php?name=" +encodeuricomponent (names) + "&mo=" +encodeuricomponent (MOS) + "&body=" + encodeURIComponent (bodys) + "&id=" +<?= $id;? >;

Ajax part is not spoken, the main encodeuricomponent used to be garbled
</body>

PHP processing method,

$name = Iconv (' utf-8 ', ' gb2312 ', Postget (' name '));

Why convert Uft-8 to gb2312, because encodeuricomponent converts strings into coded formats using UTF-8 encoding. For the utf-8 is relatively simple, and urlencode is basically interchangeable, so if you are gb2312 the page must be converted.

Of course accept the page conversion, now want to gb2312 the page return data must be
$name = Iconv (' gb2312 ', ' Utf-8 ', Postget (' name '));

Returned to the Ajax return, this solves the Ajax PHP encodeuricomponent coding problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.