The odd data in the page table is uploaded to the background through AJAX. why cannot the Chinese value be obtained? Why?

Source: Internet
Author: User
The page form data is uploaded to the background through AJAX, and the Chinese character cannot be taken? Why? JScriptcodevaruserindex = WebClient. store [0]. userIndex; varname =$ (& quot; name-input & quot ;). value; the page form data is uploaded to the background through AJAX, and the Chinese character cannot obtain the value? Why?
JScript code
           var userindex = WebClient.Store[0].UserIndex;      var name = $("name-input").value;        var phone = $("phone-input").value;        var babyname = $("babyname-input").value;        var password = $("password-input").value;                     var url = "php/login.phpaction=Modify&UserIndex="+userindex+"&Name="+name+"&Phone="+phone+"&BabyName="+babyname+"&Password="+password+"&random="+Math.random();


PHP code
      $name = "";    if(array_key_exists('Name',$_GET))    {        $name = trim($_GET['Name']);    }

Here, $ name can be displayed normally if the page data is in English, but cannot be displayed in Chinese. What's going on?

------ Solution --------------------
Encode the data with the encodeURIComponent () function before passing it to php.
------ Solution --------------------
The encoded value of ajax is utf-8. if your Chinese character is gb, it will be converted to UTF-8.
------ Solution --------------------
Discussion
JScript code

Var userindex = WebClient. Store [0]. UserIndex;
Var name = $ ("name-input"). value;
Var phone = $ ("phone-input"). value;
Var babyname = $ ("babyname-input"). val ......

------ Solution --------------------
Js
Alert (url); post the result

Php
Print_r ($ _ GET); paste the result

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.