Garbled characters appear during jqueryajax delivery

Source: Internet
Author: User
Why is garbled characters displayed when jqueryajax submits Chinese? The submit.htm code on the submission page is as follows: HTMLcode & lt ;! DOCTYPEhtmlPUBLIC & quot;-W3CDTDXHTML1.0TransitionalEN & quot; www. w3.orgTRxhtml1DTDxhtml1-transit jquery ajax submit Chinese garbled characters?
The submit.htm code is as follows:
HTML code
  
  Welcome
  ... $. Ajax ({type: "POST", url: "xx/add_post.php", data: 'AA = '+ escape ($ (' # AA '). val () + '& bb =' + $ ('# bb '). val (), success: function (html) {alert ('added successfully! ');}});....

The received data page is add_post.php.
PHP code
  
  getMessage();    }    $stmt=$pdo->prepare("insert into acom_a(aa, bb) values(:aa, :bb)");          $stmt->execute(array(":aa"=>$_POST["aa"], ":bb"=>$_POST["bb"]));?>


The aa field is garbled in Chinese, and bb is normal in English!

------ Solution --------------------
Execute add_post.php file separately to insert Chinese garbled characters?
------ Solution --------------------
EncodeURI ($ ('# bb'). val (); in this way, encodeURI is used for variables that may contain Chinese characters.
------ Solution --------------------
Discussion

Reference:
You don't seem to have the tools or capabilities to debug ajax.
$ Pdo = new PDO ("mysql: host = localhost; dbname = acom", "root", "abcdefghi", array (PDO :: MYSQL_ATTR_INIT_COMMAND => "set names utf8 "));

Your PDO settings have solved the problem. thank you!
Also ask ......

------ Solution --------------------
Discussion

Is there a way to stop executing this statement after it is modified in the configuration file?

------ Solution --------------------
The problem is solved!

Array (PDO: MYSQL_ATTR_INIT_COMMAND => "set names utf8 ")
Indicates that after the mysql result is connected, the set names utf8 command is executed immediately to set the character set for communication to UTF-8.

Because mysql databases are independent and public. Therefore, it is unlikely that you will only be installed based on the parameters you need.
Therefore, it is necessary to declare the character set during use.

Mysql is personalized for PDO. For declared character sets, he needs to execute SQL commands. if oralce is declared in dsn

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.