德codeURIComponent(URI)不工作? [英] decodeURIComponent(uri) is not working?
本文介绍了德codeURIComponent(URI)不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Ajax来发布内容,我使用 http.send(EN codeURIComponent(PARAMS));
编码...但我无法去code它们在PHP。我使用POST,所以我不认为它需要连接code?我很困惑,怎么我应该去code在PHP中值...
PARAMS = "guid="+szguid+"&username="+szusername+"&password="+szpassword+"&ip="+ip+"&name="+name+"&os="+os;
//警报(PARAMS);
document.body.style.cursor ='等待'; //改变光标等待
如果(!HTTP)
HTTP =的CreateObject();
非缓存=的Math.random();
http.open('后','addvm.php');
http.setRequestHeader(内容型,应用程序/ x-WWW的形式urlen codeD);
http.setRequestHeader(内容长度,params.length);
http.setRequestHeader(连接,关闭);
http.onreadystatechange = SaveReply;
http.send(EN codeURIComponent(PARAMS));
解决方案
连接codeURIComponent
将连接code所有和放大器; S及= s表示界定你的键/值对。您需要单独使用它的每一个部分。像这样:
PARAMS =
GUID =EN + codeURIComponent(szguid)+
&放大器;用户名=EN + codeURIComponent(szusername)+
&放大器;密码=EN + codeURIComponent(szpassword)+
&放大器; IP =EN + codeURIComponent(IP)+
&放大器;名称=EN + codeURIComponent(名)+
&放大器; OS =EN + codeURIComponent(OS);
//警报(PARAMS);
document.body.style.cursor ='等待'; //改变光标等待
如果(!HTTP)
HTTP =的CreateObject();
非缓存=的Math.random();
http.open('后','addvm.php');
http.setRequestHeader(内容型,应用程序/ x-WWW的形式urlen codeD);
http.setRequestHeader(内容长度,params.length);
http.setRequestHeader(连接,关闭);
http.onreadystatechange = SaveReply;
http.send(PARAMS);
I'm using Ajax to post contents, and I'm using http.send(encodeURIComponent(params));
for encoding ... but I'm unable to decode them in PHP. I'm using POST so I didn't think it required encode? I'm confused as to how I'm supposed to decode the values in 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
will encode all the &s and =s that delimit your key/value pairs. You need to use it on each part individually. Like so:
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);
这篇关于德codeURIComponent(URI)不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文