我正在使用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));
最佳答案
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);
关于php - encodeURIComponent(uri)无法正常工作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6053473/