开发者

Why "space" is not supported in the ajax post method?

开发者 https://www.devze.com 2022-12-20 18:01 出处:网络
Below is my html <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">

Below is my 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" na开发者_如何学JAVAme="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>

Here i facing the problem is,

When i submit "Remarks" textarea innerhtml to my "Data_Check.asp"

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

and this remarks save in my sql database.( database field is "Remarks_text" and datatype is "text")

In the data base textarea data is read ("please, accept my submit form.") textarea data with out space.

like this please,acceptmysubmitform.

I need to save please, accept my submit form.

hoping your support


Try url encoding:

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


Change

document.getElementById("Remarks").innerHTML;

to

document.getElementById("Remarks").value;


I suspect spaces are not supported in URLs or HTTP headers, hence old URLs had %20 instead of a space. Modern browsers and servers now do this behind the scenes.

I found replacing spaces with %20 using formValues = formValues.replace(/ /gi,"%20"); prior to sending solved the problem.


Yes this is fixed!

Example :

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号