js里escape是unicode编码,php不好解。
js和php的urlencode urldecode好像也不一样不知js如何传中文参数给php?
谢谢

解决方案 »

  1.   

    urlencode就行了,怎么不一样??
      

  2.   

    js的urlencode到php不是自动转么?
      

  3.   

    urlencode可以解的。这个是http传输的标准。
    把你的代码贴出来看看,是不是其他地方有问题。
      

  4.   

    这是我的一段代码,也是传递中文参数,然后修改数据库的。
    <script>
      var url="admin/ajaxmodify.php?"+key+"=";
     url+=encodeURIComponent(encodeURIComponent(value));
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    </script>
    参数是中文encodeURIComponent这个方法必须调用两次
      

  5.   

    差点忘了,后台获取参数的时候还得用个方法再decode一下
    function utf8RawUrlDecode ($source) {
        $decodedStr = "";
        $pos = 0;
        $len = strlen ($source);
        while ($pos < $len) {
            $charAt = substr ($source, $pos, 1);
            if ($charAt == '%') {
                $pos++;
                $charAt = substr ($source, $pos, 1);
                if ($charAt == 'u') {
                    // we got a unicode character
                    $pos++;
                    $unicodeHexVal = substr ($source, $pos, 4);
                    $unicode = hexdec ($unicodeHexVal);
                    $entity = "&#". $unicode . ';';
                    $decodedStr .= utf8_encode ($entity);
                    $pos += 4;
                }
                else {
                    // we have an escaped ascii character
                    $hexVal = substr ($source, $pos, 2);
                    $decodedStr .= chr (hexdec ($hexVal));
                    $pos += 2;
                }
            } else {
                $decodedStr .= $charAt;
                $pos++;
            }
        }
        return $decodedStr;
    }
    这是php的。
      

  6.   

    要用 encodeURIComponent 函数进行 url 编码注意 encodeURIComponent函数是将传入的参数转换成utf-8编码以后再做URL编码,所以你可能需要在php程序中做编码转换
      

  7.   

    如果全部是utf-8可以直接传递
      

  8.   

    其实没那复杂的,ajax默认是uft8的,那我在接受设置为uft-8或者利用相关函数转换成其它编码就成了。