繁体   English   中英

如何从ajax发布请求中获取参数

[英]How to fetch parameters from ajax post request

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并做一些有用的事情,但是看来我缺少了一些东西。 响应为(空字符串)。 任何帮助是一种赞赏!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM