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

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

WBOY
WBOYOriginal
2016-06-13 10:34:44955browse

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

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']);    }

这里$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); 贴出结果
Statement:
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