日期:2014-05-17  浏览次数:20807 次

asp+xmlhttp
HTML code
<%
set xmlhttp=Server.CreateObject("MSXML2.ServerXMLHTTP")
 dim xmlstr
 dim URL
xmlstr="<info><rec><depID>1</depID><smallClassID>20040212200856429814</smallClassID><type>1,3</type><keyWord>关键字1, 关键字2</keyWord><title>新闻标题</title><author>作者</author><original>原出处</original><content>新闻内容</content></rec></info>"
  
URL="http://10.10.12.36:80/receiveInfo.asp"
dim xmlDoc
xmlhttp.open "GET","http://10.10.12.36:80/menu.xml",false 
xmlhttp.send(null)

xmlDoc=xmlhttp.responseText
xmlstr=xmlDoc

response.Write(xmlDoc)
xmlhttp.open "POST",URL, false
xmlhttp.send(xmlstr)


if  err.number=0 then
response.Write(xmlhttp.status)
response.Write(xmlHttp.ResponseText)
       if xmlhttp.status <>"200" then
              Response.Write "<font style='font-size:12px;color:red'>状态:"&xmlhttp.status&" ;描述:"&xmlHttp.ResponseText&"</font>"
       else
              Response.Write "<font style='font-size:12px;color:red'>  "&xmlHttp.ResponseText&"</font>"
       end if
else
       Response.Write "<font style='font-size:12px;color:red'>状态:"&xmlhttp.status&" ;描述:"&xmlHttp.ResponseText&"</font>"
end if

%>



如果用xmlstr=xmlDoc,把xmlstr传过去,receiveInfo.asp页面xmldoc.load Request可以接收到数据,但是如果直接用赋值给xmlstr的那个数据,receiveInfo.asp页面xmldoc.load Request的数据为空,menu.xml里面的数据和赋值给xmlstr的那个数据一样的,求教怎么回事,为什么直接传过去不行呢??那个网上写的代码就是直接传过去,而不是需要从menu.xml里面读取啊

------解决方案--------------------
Set xmlDoc=xmlhttp.responseXML


response.Write(xmlDoc.xml)
xmlhttp.open "POST",URL, false
xmlhttp.send(xmlDoc.xml)

或者
xmlhttp.send(xmlDoc)
------解决方案--------------------
先膜拜楼上的
------解决方案--------------------
xmlDoc.xml就是字符串啊

post方法需要加

var params = "data=" + escape(xmlDoc.xml);
xmlhttp.open "POST",URL, false
//需要加
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params)
------解决方案--------------------
application/x-www-form-urlencoded