开发者

Ajax and VbScript: fetching Post variable in test.asp

current i am trying to use ajax for my site ....... because 开发者_开发问答of size of data is not limited i need to use post method for send data to database but the problem is i am unable to fetch the Post variables in the test.asp

here is the script i am using

function SaveData(content ) 
{
    var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    msg=xmlhttp.responseText;
    alert(msg);
    }
  }

 var para = encodeURIComponent("content="+content)
xmlhttp.open("POST","test.asp",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xmlhttp.send(para)

}

and here is test.asp code

t = Request.form("content")
Response.write(t)

please help me solving this problem of fetching the Post method variable in test.asp

if possible any one can share code of jquery ajax with post method in asp classic too that would also be helpful


You need to change this:

var para = encodeURIComponent("content="+content)

into this:

var para = "content=" + encodeURIComponent(content);

The way that it was, you were submitting something like this to the server:

content%3Dtest%20data%20123

With the adjusted line of code, you're submitting something like this, which is as it should be:

content=test%20data%20123

Have you considered using a JavaScript library such as jQuery? A library will abstract away all this unpleasantness:

$.post("test.asp", { 'content': content }, function(data) {
    alert("Returned data: " + data);
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜