我使用Ajax发布内容,并使用http.send(encodeURIComponent(params));进行编码...但我无法在PHP中解码它们。我正在使用POST,所以我不认为它需要编码?我对如何解码PHP中的值感到困惑……
params = "guid="+szguid+"&username="+szusername+"&password="+szpassword+"&ip="+ip+"&name="+name+"&os="+os;
//alert(params);
document.body.style.cursor = 'wait';//change cursor to wait
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(encodeURIComponent(params));发布于 2011-05-19 11:41:04
encodeURIComponent将对分隔键/值对的所有&s和=s进行编码。您需要在每个部件上单独使用它。如下所示:
params =
"guid=" + encodeURIComponent(szguid) +
"&username=" + encodeURIComponent(szusername) +
"&password=" + encodeURIComponent(szpassword) +
"&ip=" + encodeURIComponent(ip) +
"&name=" + encodeURIComponent(name) +
"&os=" + encodeURIComponent(os);
//alert(params);
document.body.style.cursor = 'wait';//change cursor to wait
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);发布于 2011-05-19 11:49:12
如果您正在提交来自JS的编码值,并且想要在PHP中decode它们,您可以这样做:
// decode POST values so you don't have to decode each pieces one by one
$_POST = array_map(function($param) {
return urldecode($param);
}, $_POST);
// assign post values after every value is decodedhttps://stackoverflow.com/questions/6053473
复制相似问题