首页 新闻 会员 周边 捐助

ASHX程序如何返回数据对象

0
悬赏园豆:5 [已关闭问题]
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">各位园友,问个问题:现在我想做一个对文章评论系统,想利用</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">JQuery</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">和</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">ASHX</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">读取评论内容进行无刷新显示。</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"></span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">假如评论的数据包括:姓名,邮箱,日期,评论内容等。这些栏位都定义在一个实体类里面,比如</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">Reply</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">类中。现在我想要页面载入的时候就加载评论,每</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">10</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">条为一页。在</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">ASHX</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">里面用</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">SQL</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">进行分页读取</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">10</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">条数据之后请问如何返回这些数据呢?</span><span style="font-family: Times New Roman;"><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="ZH-CN"> </span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US">ASHX</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">程序只能返回</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">string</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">类型不能返回其他的类型。请问如何才能返回数据对象的集合呢?</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"></span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">PS</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">:有方法说用</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">Json</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">格式的数据返回。但我不知道怎么去做,网上相关资料较少。各位高手可否给个</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">Demo</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">或者思路,代码段都行</span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"><span style="font-family: Times New Roman;">~</span></span><span style="font-family: SimSun; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN;" lang="ZH-CN">谢谢!</span></span><span style="mso-fareast-language: ZH-CN; mso-fareast-font-family: SimSun;" lang="EN-US"></span></p>
SAP梦心的主页 SAP梦心 | 初学一级 | 园豆:67
提问于:2009-09-28 11:00
< >
分享
其他回答(2)
0

通过ASHX传数据,其实跟通过WebService传差不多,只不过WEBService传送的时候,会把你在程序里写的返回的列表自动序列化成XML形式返回给客户端。所在在ASHX里返回数据,你所要做的就是把你的实体类,转化成XML格式,或者是JSON格式。至于怎么转化,网上一搜一大堆,在3.5框架里,本身就带了一个方法,可以直接把实体类转化成JSON格式的

李.net | 园豆:730 (小虾三级) | 2009-09-28 11:05
0

http://www.cnblogs.com/xingshao/archive/2009/09/28/json.html

ashx+Json 返回数据集、你需要的。

邢少 | 园豆:10926 (专家六级) | 2009-09-28 12:08
0

网上的资料不少啊

1.ASHX端准备数据:不知道你用什么,我用的datatable2Json直接将datatable转换成Json,这个里面可以加GZip,可以作缓存。

2.客户端接收:JQuery有JSON的插件,也有Grid的插件,get回数据组织一下就好了

BinDai | 园豆:200 (初学一级) | 2009-09-29 11:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册