Ajax post数据在服务器端怎么取。
Ajax post数据在服务器端怎么取。
get取没问题,post没取到
var url= "WebForm1.aspx ";
xmlHttp.open( "POST ",url,true);
xmlHttp.onreadystatechange = writeNewMessage;
xmlHttp.send( "action=send "+
"&lastId= "+lastId);
[解决办法]
Request.Form[ "action "]
Request.Form[ "lastId "]
[解决办法]
xmlHttp.send( "action=send "+
"&lastId= "+lastId);
把这个,接在URL里
xmlHttp.send( " ");试试,如果还有问题,说明是JS代码问题
[解决办法]
关注,曾遇过,没解决
[解决办法]
无私奉献了
<script type=text/javascript>
var XMLHttp;
function CreateXMLHttpRequest()
{
if(window.ActiveXObject)
{
XMLHttp=new ActiveXObject( "Microsoft.XMLHTTP ");
}
else if(window.XMLHttpRequest)
{
XMLHttp=new XMLHttpRequest();
}
}
function CreateQueryString()
{
//创建查询字符串
var scpID=form1.cpID.value;
var scpMC=form1.cpMC.value;
var slylb=form1.lylb.value;
var szuozhe=form1.announce_zuozhe.value;
var snote=form1.announce_note.value;
var sQueryString= "cpID= "+scpID+ "&cpMC= "+scpMC;
sQueryString+= "&lylb= "+slylb+ "&announce_zuozhe= "+szuozhe;
sQueryString+= "&announce_note= "+snote;
return sQueryString;
}
function CreateXMLString()
{
//创建XML文档
var scpID=form1.cpID.value;
var scpMC=form1.cpMC.value;
var slylb=form1.lylb.value;
var szuozhe=form1.announce_zuozhe.value;
var snote=form1.announce_note.value;
var sXMLString= " <RequestParams> ";
sXMLString+= " <Action> CPLiuyan <\/Action> ";
sXMLString+= " <cpID> "+scpID+ " <\/cpID> ";
sXMLString+= " <cpMC> "+scpMC+ " <\/cpMC> ";
sXMLString+= " <lylb> "+slylb+ " <\/lylb> ";
sXMLString+= " <announce_zuozhe> "+szuozhe+ " <\/announce_zuozhe> ";
sXMLString+= " <announce_note> "+snote+ " <\/announce_note> ";
sXMLString+= " <\/RequestParams> ";
return sXMLString;
}
function SendRequestUsingPost()
{
////利用get方法,查询串名/值作为一对附加到目标URL的后面
//CreateXMLHttpRequest();
//var PostUrl= "PostLiuyan.aspx? ";
//PostUrl+=CreateQueryString()+ "&tmpcode= "+new Date().getTime();
//XMLHttp.open( "GET ",PostUrl,true);
//XMLHttp.onreadystatechange=HandleStateChange;
//XMLHttp.send(null);
////利用post方法,把查询串作为请求体的一部分发送出去
//CreateXMLHttpRequest();
//var PostUrl= "PostLiuyan.aspx?tmpcode= "+new Date().getTime();
//XMLHttp.open( "POST ",PostUrl,true);
//XMLHttp.onreadystatechange=HandleStateChange;
//XMLHttp.setRequestHeader( "Content-Type ", "applicatioin/x-www-form-urlencoded; ");
//XMLHttp.send(CreateQueryString());
////利用post方法,把XML文档作为请求体的一部分发送出去
CreateXMLHttpRequest();
var PostUrl= "PostLiuyan.aspx?tmpcode= "+new Date().getTime();
XMLHttp.open( "POST ",PostUrl,true);
XMLHttp.onreadystatechange=HandleStateChange;
XMLHttp.setRequestHeader( "Content-Type ", "applicatioin/x-www-form-urlencoded; ");
XMLHttp.send(CreateXMLString());
}
function HandleStateChange()
{
if(XMLHttp.readyState==4)
{
if(XMLHttp.status==200)
{
alert(XMLHttp.responseText);
form1.announce_zuozhe.value= " ";
form1.announce_note.value= " ";
form1.announce_zuozhe.focus();
}
}
}
</script>
function SendRequestUsingPost() 里面用了三种方法发送数据
第一种用 Request.QueryString() 就可以接受
第二种和第三种用下面的方法
//接收利用POST方法发送过来的查询串,适用于大数据量传输
System.IO.Stream instream = Page.Request.InputStream;
System.IO.BinaryReader br = new System.IO.BinaryReader(instream, System.Text.Encoding.UTF8);
byte[] byt = br.ReadBytes((int)instream.Length);
string args = System.Text.Encoding.UTF8.GetString(byt);
args里面就是接受到的信息了
[解决办法]
Request.Form[ "action "]
Request.Form[ "lastId "]
----------------------------------
这个我试过了,不行啊