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

时间:2013-12-03 20:24:56

标签: 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();
} 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);
}

和ASP文件:

<%
response.expires=-1

x = Request.Form("html")

response.write x
%>

我需要获取传递给xmlhttp.send()方法的str并做一些有用的东西,但看起来我错过了什么。响应是(空字符串)。任何帮助都是一种欣赏!

1 个答案:

答案 0 :(得分:1)

添加请求标头可以解决问题。

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