Home > Backend Development > PHP Tutorial > 页面表奇数据通过AJAX传到后台,中文取不到值?为什么

页面表奇数据通过AJAX传到后台,中文取不到值?为什么

WBOY
Release: 2016-06-13 10:34:44
Original
1085 people have browsed it

页面表单数据通过AJAX传到后台,中文取不到值?为什么?

JScript code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->         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();
Copy after login


PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->    $name = "";    if(array_key_exists('Name',$_GET))    {        $name = trim($_GET['Name']);    }
Copy after login

这里$name 如果页面数据时英文,值能正常显示,但是是中文就显示不了 。怎么回事?

------解决方案--------------------
将数据经 encodeURIComponent() 函数编码后再传给php .
------解决方案--------------------
ajax传值的编码是utf-8,如果你中文是gb的,就要转成utf-8了
------解决方案--------------------
探讨
JScript code

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

------解决方案--------------------
js
alert(url); 贴出结果

php
print_r($_GET); 贴出结果
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template