xmlhttp:演示后台POST一个XML数据流到数据库的示例
2005-10-27 23:51
501 查看
test.htm
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<form method="post" action="postxml.asp">
<P><INPUT name="mobile" type="text"></P>
<P><INPUT id=button1 type=submit ></P>
</form>
</BODY>
</HTML>
postxml.asp文件
<%@ Language=VBScript %>
<HTML>
<BODY>
<%
dim v
v=Request("mobile")
dim i, strxml
'构造xml串
strxml = "<?xml version='1.0' encoding='gb2312' ?>"
strxml = "<chuandi>"
strxml = strxml & "<mobile>" & v & "</mobile>"
strxml = strxml & "</chuandi>"
%>
<%
'使用xmlhttp发送
dim xmlhttp
set xmlhttp = server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "POST", "http://localhost/xml/xmlhttp/getxml.asp", False
xmlhttp.send strxml
'如果错误
If xmlhttp.Status <> 200 Then
Response.Write "发生了错误"
Response.End
End If
这里的功能主要是得到提交后返回的信息
ResponseXml返回有一些问题,ResponseText返回正常
'直接使用ResponseText可以得到
response.Write xmlhttp.ResponseText
%>
</BODY>
</HTML>
getxml.asp文件,你可以不需要数据库,我只是为了测试,需要自己建一个access表
<%@ Language=VBScript %>
<%
set conn=Server.CreateObject("ADODB.connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("web.mdb")
'这里需要修改,返回客户的xml响应文档
Response.ContentType = "text/xml"
dim xmldom
' set xmldom = Server.CreateObject("Microsoft.XMLDOM")
set xmldom = Server.CreateObject("MSXML.DOMDocument")
xmldom.load Request
dim mobile
mobile = xmldom.selectSingleNode("//mobile").text
on error resume next
'使用数据库只是为了测试数据传递过来
strsql="insert into test(sid,name) values('001','"& mobile &"')"
'response.write strsql
conn.execute strsql
if err.number=0 then
retval="数据成功提交"
else
retval="数据提交失败,请检查你的数据"
end if
set xmldom = Nothing
set conn=nothing
'下面的代码是将结果以xml形式返回
'需要加上<?xml version="1.0" encoding="gb2312"?>这句,否则无法返回中文
%>
<?xml version="1.0" encoding="gb2312"?>
<kaitong>
<chengong>Y</chenggong>
<mobile><%=mobile%></mobile>
</kaitong>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<form method="post" action="postxml.asp">
<P><INPUT name="mobile" type="text"></P>
<P><INPUT id=button1 type=submit ></P>
</form>
</BODY>
</HTML>
postxml.asp文件
<%@ Language=VBScript %>
<HTML>
<BODY>
<%
dim v
v=Request("mobile")
dim i, strxml
'构造xml串
strxml = "<?xml version='1.0' encoding='gb2312' ?>"
strxml = "<chuandi>"
strxml = strxml & "<mobile>" & v & "</mobile>"
strxml = strxml & "</chuandi>"
%>
<%
'使用xmlhttp发送
dim xmlhttp
set xmlhttp = server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "POST", "http://localhost/xml/xmlhttp/getxml.asp", False
xmlhttp.send strxml
'如果错误
If xmlhttp.Status <> 200 Then
Response.Write "发生了错误"
Response.End
End If
这里的功能主要是得到提交后返回的信息
ResponseXml返回有一些问题,ResponseText返回正常
'直接使用ResponseText可以得到
response.Write xmlhttp.ResponseText
%>
</BODY>
</HTML>
getxml.asp文件,你可以不需要数据库,我只是为了测试,需要自己建一个access表
<%@ Language=VBScript %>
<%
set conn=Server.CreateObject("ADODB.connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("web.mdb")
'这里需要修改,返回客户的xml响应文档
Response.ContentType = "text/xml"
dim xmldom
' set xmldom = Server.CreateObject("Microsoft.XMLDOM")
set xmldom = Server.CreateObject("MSXML.DOMDocument")
xmldom.load Request
dim mobile
mobile = xmldom.selectSingleNode("//mobile").text
on error resume next
'使用数据库只是为了测试数据传递过来
strsql="insert into test(sid,name) values('001','"& mobile &"')"
'response.write strsql
conn.execute strsql
if err.number=0 then
retval="数据成功提交"
else
retval="数据提交失败,请检查你的数据"
end if
set xmldom = Nothing
set conn=nothing
'下面的代码是将结果以xml形式返回
'需要加上<?xml version="1.0" encoding="gb2312"?>这句,否则无法返回中文
%>
<?xml version="1.0" encoding="gb2312"?>
<kaitong>
<chengong>Y</chenggong>
<mobile><%=mobile%></mobile>
</kaitong>
相关文章推荐
- Web前端 测试数据接口url,如何post一个XML字符串,点击保存就可以保存到数据库
- 腾讯云图片鉴黄集成到C# SQL Server 怎么在分页获取数据的同时获取到总记录数 sqlserver 操作数据表语句模板 .NET MVC后台发送post请求 百度api查询多个地址的经纬度的问题 try{}里有一个 return 语句,那么紧跟在这个 try 后的 finally {}里的 code 会 不会被执行,什么时候被执行,在 return 前还是后? js获取某个日期
- 演示一个TDE的数据加密示例,并用logminer验证加密效果
- JAVA程序通过后台登陆网站,获取Session,然后再POST Http Request添加数据到数据库的实例
- 演示一个OLS进行数据访问控制的示例
- 数据库操作_连接SQL Server数据库示例;连接ACCESS数据库;连接到 Oracle 数据库示例;SqlCommand 执行SQL命令示例;SqlDataReader 读取数据示例;使用DataAdapter填充数据到DataSet;使用DataTable存储数据库表;将数据库数据填充到 XML 文件;10 使用带输入参数的存储过程;11 使用带输入、输出参数的存储过程示;12 获得数据库中表的数目和名称;13 保存图片到SQL Server数据库示例;14 获得插入记录标识号;Exce
- 一个AJAX列子,通过读取后台数据库数据转换为xml格式进行输出
- C# 后台模拟Post Xml数据 并接受
- 使用 NodeJs 实现一个本地接口数据系统,无需数据库,让前端独立于后台开发
- Asp.net XMLHTTP 基类 (GET,Post发送XML数据)
- form 表的post提交,其中一个超多数据的input标签在后台获取数据被截断的解决方法
- 演示一个VPD进行数据访问控制的示例
- 演示一个VPD进行数据访问控制的示例
- 从数据库得到数据导出指定格式的xml文件,上传到NC接口,返回回执到本地一个xml文件
- Chrome 下,重复使用 XMLHttpRequest进行Post数据时,遇到一个奇怪的问题
- Android通过post请求发送一个xml,解析返回xml数据
- 一个好用的测试服务器接口的工具(post请求,xml,json等数据格式)
- 从数据库得到数据导出指定格式的xml文件,上传到NC接口,返回回执到本地一个xml文件(接上篇补充)
- ajax xmlhttprequest使用post传参数并向后台获取数据
- FOR XML AUTO将数据库表的一个字段的数据查询拼接为带间隔符的字符串