AJAX POST 和加号 ( + ) 和 (&) 签名如何编码


AJAX POST and Plus ( + ) and (&) Sign How to 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 端适当地"解码"它?

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

尝试:

JS: encodeURIComponent (/* url */);

PHP: urldecode (/* url */);