为什么ajax post方法不支持“space”?

时间:2010-02-18 07:32:23

标签: javascript ajax asp-classic

以下是我的HTML

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script type="text/javascript">
function Data_Check()
{
var xmlHttp;

try
  {  
  xmlHttp=new XMLHttpRequest();  }
catch (e)
  { 
   try
    {    
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");   
     }
  catch (e)
    {   
     try
      {     
       xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   
          }
    catch (e)
      {      
      alert("Your browser does not support AJAX!");      
      return false; 
           }    
           } 
            }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      alert(xmlHttp.responseText);
      }
    }   

    var RES = document.getElementById("Remarks").innerHTML;
    var params ="RES="+RES;
    xmlHttp.open("POST","Data_Check.asp",true);       
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(params);

   }
</script>
</head>

<body>
<textarea id="Remarks" rows="5" name="Remarks" cols="79" style="font-family: Arial; font-size: 11px">please, accept my submit form.</textarea>

<br>
<img id="Submit" onclick ="return Data_Check();" border="0" src="submit.png" width="145" height="28">
</body>
<img
</html>

我面临的问题是,

当我将“备注”textarea innerhtml提交给我的“Data_Check.asp”时

<%
RES = Request.Form("RES")
%>

此备注保存在我的sql数据库中。(数据库字段为“Remarks_text”,数据类型为“text”)

在数据库中,textarea数据被读取(“请,接受我的提交表单。”)textarea数据,没有空格。

像这样 请,acceptmysubmitform。

我需要保存 请接受我的提交表单。

希望得到您的支持

4 个答案:

答案 0 :(得分:12)

尝试网址编码:

var RES = encodeURIComponent(document.getElementById("Remarks").value);

答案 1 :(得分:0)

更改

document.getElementById("Remarks").innerHTML;

document.getElementById("Remarks").value;

答案 2 :(得分:0)

我怀疑URL或HTTP标头不支持空格,因此旧网址有%20而不是空格。现代浏览器和服务器现在在幕后执行此操作。

我发现在发送解决问题之前使用%20formValues = formValues.replace(/ /gi,"%20");替换空格。

答案 3 :(得分:0)

是的,这是固定的!

示例:

var dataString = "textcontent="+test.replace(/ /gi,"%20");

相关问题