AJAX POST和Plus(+)和(&)签署如何编码?

时间:2011-05-18 11:01:28

标签: php ajax post decode encode

我正在通过AJAX to a PHP script并使用此代码

发布表单字段的内容
if(!http)
            http = CreateObject();  

        nocache = Math.random();

        http.open('post', 'addvm.php');
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
        http.setRequestHeader("Content-length", params.length);
        http.setRequestHeader("Connection", "close");
        http.onreadystatechange = SaveReply;

        http.send(params);

问题是任何+ and &标志都被剥离并被替换。如何安全地“编码”+ and &符号,然后在PHP端对其进行适当的'解码'?

2 个答案:

答案 0 :(得分:2)

尝试:

js:encodeURIComponent (/* url */);

php:urldecode (/* url */);

答案 1 :(得分:2)

需要编码你的参数encodeURIComponent 注意: - 当您访问$_GET, $_POST or $_REQUEST in PHP时,您正在检索已经解码的值。