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