Chinese parameter garbled characters passed by jquery ajax and Solutions

Source: Internet
Author: User

JQuery passed Chinese parameters garbled, because the default transfer method is not using UTF-8, all we can pass the parameter encoding, and then operate, the Code is as follows, the red code is the passed parameter, marked
Copy codeThe Code is as follows:
Smsubmitclick = function (){
$ (Document). ready (function (){
Var name = $ ("# txt_name"). val ();
Var type = $ ("# seltype option: selected"). val ();
Var zjnum = $ ("# txt_num"). val ();
If (name = null | name = "")
{
Alert ("Enter your real name ");
Return false;
}
If (name. length> 20)
{
Alert ("sorry, your user name has an exception. Please enter it again ");
$ ("# Txt_name"). focus ();
$ ("# Txt_name"). val ("");
Return false;
}
If (zjnum = null | zjnum = "")
{
Alert ("Enter your ID card number ");
Return false;
}
If (zjnum. length> 30)
{
Alert ("sorry, your credential is abnormal. Please enter it again ");
$ ("# Txt_num"). focus ();
$ ("# Txt_num"). val ("");
Return false;
}
Else
{
$. Ajax ({
Type: "get ",
Cache: false,
ContentType: "application/x-www-form-urlencoded: charsets = UTF-8 ",
Url: "ajaxpage. aspx? T = smrz & name = "+ escape (name) +" & zjtype = "+ escape (type) +" & zjnum = "+ escape (zjnum) + "",
DataType: "json ",
Success: function (data ){
Alert (data.info );
}
})
}
})

}

Related Article

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.