Javascript 如何从ajax post请求中获取参数

Javascript 如何从ajax post请求中获取参数,javascript,ajax,asp-classic,Javascript,Ajax,Asp Classic,Javascript代码是: var str = "html=<p>Some htmlcode here<p><div>more htmlcode </div>"; saveProject(str); function saveProject(str) { if (str=="") { return; } if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } el

Javascript代码是:

var str = "html=<p>Some htmlcode here<p><div>more htmlcode </div>";
saveProject(str);

function saveProject(str) {
if (str=="") {
    return;
}
if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
} else {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        console.log(xmlhttp.responseText);
    }
}
xmlhttp.open("POST","../demo.asp",true);
xmlhttp.send(str);
}
var str=“html=此处的一些html代码更多html代码”;
储蓄项目(str);
功能保存项目(str){
如果(str==“”){
返回;
}
if(window.XMLHttpRequest){
xmlhttp=新的XMLHttpRequest();
}否则{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
log(xmlhttp.responseText);
}
}
open(“POST”、“./demo.asp”,true);
xmlhttp.send(str);
}
和ASP文件:

<%
response.expires=-1

x = Request.Form("html")

response.write x
%>


我需要获取传递给xmlhttp.send()方法的str并执行一些有用的操作,但是看起来我缺少了一些东西。响应为(空字符串)。任何帮助都是一种感激

添加请求头可以解决此问题

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

添加请求头可以解决这个问题

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

尝试将str包装成
encodeURIComponent
-
xmlhttp.send(encodeURIComponent(str))
。现在只有post是编码的str,但响应仍然是空字符串。它不是
response.Write(x)
Write syntax.VBscript不区分大小写。写“某种状态”是完全正确的陈述。虽然我试着用这个语句来回答。仍然是一个空字符串。同样如果我response.write“test”。响应实际上已经传递。所以它是Response.Form或.send()方法的一部分,尝试将str包装成
encodeURIComponent
-
xmlhttp.send(encodeURIComponent(str))
。现在只有post是编码的str,但响应仍然是空字符串。它不是
response.Write(x)
Write syntax.VBscript不区分大小写。写“某种状态”是完全正确的陈述。虽然我试着用这个语句来回答。仍然是一个空字符串。同样如果我response.write“test”。响应实际上已经传递。这是Response.Form或.send()方法