目前我正在尝试为我的网站使用 ajax ....... 因为数据的大小不受限制我需要使用 post 方法将数据发送到数据库但问题是我无法获取 Post test.asp 中的变量
这是我正在使用的脚本
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)
}
这里是test.asp代码
t = Request.form("content")
Response.write(t)
请帮我解决在test.asp中获取Post方法变量的问题
如果可能的话,任何人都可以在 asp classic 中使用 post 方法共享 jquery ajax 代码,这也会有所帮助
最佳答案
你需要改变这个:
var para = encodeURIComponent("content="+content)
进入这个:
var para = "content=" + encodeURIComponent(content);
当时的情况是,您向服务器提交了类似这样的内容:
content%3Dtest%20data%20123
使用调整后的代码行,您提交的内容应该是这样的:
content=test%20data%20123
您是否考虑过使用 JavaScript 库,例如 jQuery ?图书馆将abstract away所有这些不愉快:
$.post("test.asp", { 'content': content }, function(data) {
alert("Returned data: " + data);
});
关于javascript - Ajax 和 VbScript : fetching Post variable in test. asp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5455710/