Asp读取SQL记录,转换成JSON,提交给WebService

Junyov 2020-05-25 07:08:54
各位好,咨询大家一个问题,Asp查询的Sql值如何转换成JSON格式,提交给WebService,感谢!
<%
dim conn
dim rs
set conn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
conn.Open connstring

sql="select * from Application where ApplyNoID="&request("ApplyNoID")&""
set rs=conn.Execute(sql)
%>

<html>
<head>
<LINK href="../global.css" rel=STYLESHEET type=text/css>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%request("ApplyNoID")%></title>
</head>
<script src="../tools/jquery.min.js"></script>
<script language="JavaScript">
function window_onload()
{
window.moveTo(-2,-2);
window.resizeTo(screen.availWidth, screen.availHeight);
}

</script>
<script type="text/javascript">

$(function () {
$("#btn").click(function () {
var jsonObj = {};
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
url: "http://localhost:8080/Application.asmx/Application1",

data:JSON.stringify({"jsonStr":JSON.stringify(jsonObj)}),
success: function (data) {
alert(data.d);
},
error: function (data) {
alert($.parseJSON(data.responseText).Message);},
});
});

})

</script>
<body bgcolor="#ffffff" onLoad="window_onload()">
<table width="100%" height="30" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<input type="button" name="" id="btn" value="审核提交" />
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="DECFAD">
<tr>
<td width="10%" height=20 align=center bgcolor="DEDFDE">编号</td>
<td width="25%" align=center bgcolor="efefef"><%=rs("no")%></td>
<td width="10%" align=center bgcolor="DEDFDE">名称</td>
<td width="20%" align=center bgcolor="efefef"><%=rs("name")%></td>
</tr>
</table>

<%
dim connorderline
dim rsorderline
set connorderline=server.CreateObject("adodb.connection")
set rsorderline=server.CreateObject("adodb.recordset")
connorderline.Open connstring
rsorderline.Open "select * from Applicationline where ApplyNoID="&request("ApplyNoID"),connorderline,1,1
%>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><strong><font size="2"><b><font class="title">项目明细</font></b></font></strong></td>
</tr>
<tr>
<td height=2 colspan="2" bgcolor="#4A699C"></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="DECFAD">
<tr bgcolor="efefef">
<td width="3%" height="15" align=center>序号</td>
<td width="4%" height="15" align=center>型号</td>
<td width="4%" height="15" align=center>数量</td>
</tr>
<%i=1
do while not rsorderline.EOF%>
<tr bgcolor="#FFFFFF">
<td align=center><%=i%></td>
<td align=center><%=rsorderline("model")%></td>
<td align=center><%=rsorderline("qty")%></td>
</tr>
<%
i=i+1
rsorderline.MoveNext
loop

rsorderline.Close
set rsorderline=nothing
connorderline.Close
set connorderline=nothing
%>
</table>
</body>
</html>


...全文
7641 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
浴火_凤凰 2020-06-29
  • 打赏
  • 举报
回复
字符串拼接成json吧 或者百度看看有没有第三方的库可以直接使用的
kevin82819 2020-06-23
  • 打赏
  • 举报
回复
直接用json插件(json.asp网上很多),然后SQL输入json格式数据,做成api接口,前端再用js调取不就可以了吗
Junyov 2020-05-27
  • 打赏
  • 举报
回复
引用 1 楼 hookee 的回复:
1 用字符串拼接方式把数据拼成 json格式,拼接时要把js字符串的几个特殊字符转义。 2 先要了解webservice要求的wsdl请求格式是什么,然后用 pocketSoap之类的第三方组件拼接请求头后递交数据。https://www.pocketsoap.com/pocketsoap/
你好,感谢回答。 现在就是如何拼接的问题,详细表单样式与json样式见以下链接: https://bbs.csdn.net/topics/396671819 接口要求类型,可以拼接后再转换,这个问题不大。
hookee 2020-05-27
  • 打赏
  • 举报
回复
1 用字符串拼接方式把数据拼成 json格式,拼接时要把js字符串的几个特殊字符转义。 2 先要了解webservice要求的wsdl请求格式是什么,然后用 pocketSoap之类的第三方组件拼接请求头后递交数据。https://www.pocketsoap.com/pocketsoap/

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧