使用http.send()ajax

时间:2012-05-03 18:23:12

标签: javascript ajax

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'有空格时,有什么解决方案可以获得确切的字符串吗?

2 个答案:

答案 0 :(得分:1)

PHP:

$field = urldecode($_POST['field']);

答案 1 :(得分:0)

您同时使用escapeencodeURI双重转发数据。另外,我建议您改用encodeURIComponent。尝试改为:

var poststr = "field=" + encodeURIComponent(callerName) + 
  "&op=add&nocache=" + nocache;