[英]How to fetch parameters from ajax post request
The Javascript code is: 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);
}
and the ASP file: 和ASP文件:
<%
response.expires=-1
x = Request.Form("html")
response.write x
%>
I need to fetch the str passed to xmlhttp.send() method and do some useful stuffs, but it looks like I'm missing something. 我需要获取传递给xmlhttp.send()方法的str并做一些有用的事情,但是看来我缺少了一些东西。 The response is (an empty string).
响应为(空字符串)。 Any help is a appreciate!
任何帮助是一种赞赏!
添加请求标头可以解决此问题。
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.