0
if(document.getElementById(callerName).checked) {
    //alert(callerName);        
    var poststr = "field=" + escape(encodeURI(callerName)) +
      "&op=add" + "&nocache=" + nocache;
}
else {
    //alert(callerName);
    var poststr = "field=" + escape(encodeURI(callerName)) + 
      "&op=del" + "&nocache=" + nocache;
}
http.send(poststr);

当我收到$_POST['field']'%20'时,有空格..任何解决方案来获得准确的字符串?

4

2 回答 2

1

PHP:

$field = urldecode($_POST['field']);
于 2012-05-03T18:26:21.643 回答
0

您同时使用escape和对数据进行双重转义encodeURI。另外,我建议您encodeURIComponent改用。尝试更改为:

var poststr = "field=" + encodeURIComponent(callerName) + 
  "&op=add&nocache=" + nocache;
于 2012-05-03T18:26:28.040 回答