服务器端代码:
1 using System;
2 using System.Configuration;
3 using System.Data;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.HtmlControls;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.Services;
11
12 public partial class _Default : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16
17 }
18
19 [WebMethod]
20 public static string ShowDetailData(string user)
21 {
22 return user+"你好!你知道下面的文字选自哪里么?<br/>"+ "郭靖知道师父虽然摔下,并不碍事,但欧阳锋若乘势追击,后着可凌厉之极,当下叫道:“看招!”左腿微屈,右掌划了个圆圈,平推出去,正是降龙十八掌中的“亢龙有悔”。这一招他日夕勤练不辍,初学时便已非同小可,加上这十余年苦功,实已到炉火纯青之境,初推出去时看似轻描淡写,但一遇阻力,能在刹时之间连加一十三道后劲,一道强似一道,重重叠叠,直是无坚不摧、无强不破。这是他从九阴真经中悟出来的妙境。纵是洪七公当年,单以这一招而论,也无如此精奥的造诣。";
23 }
24 }
25
2 using System.Configuration;
3 using System.Data;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.HtmlControls;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.Services;
11
12 public partial class _Default : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16
17 }
18
19 [WebMethod]
20 public static string ShowDetailData(string user)
21 {
22 return user+"你好!你知道下面的文字选自哪里么?<br/>"+ "郭靖知道师父虽然摔下,并不碍事,但欧阳锋若乘势追击,后着可凌厉之极,当下叫道:“看招!”左腿微屈,右掌划了个圆圈,平推出去,正是降龙十八掌中的“亢龙有悔”。这一招他日夕勤练不辍,初学时便已非同小可,加上这十余年苦功,实已到炉火纯青之境,初推出去时看似轻描淡写,但一遇阻力,能在刹时之间连加一十三道后劲,一道强似一道,重重叠叠,直是无坚不摧、无强不破。这是他从九阴真经中悟出来的妙境。纵是洪七公当年,单以这一招而论,也无如此精奥的造诣。";
23 }
24 }
25
客户端代码:
1 <script type="text/javascript">
2 //下面的脚本调用WebService取回数据显示在webserviceDataDiv
3
4 <script type="text/javascript">
5 function getDataByServerMethod()
6 {
7 PageMethods.ShowDetailData($get('Text1').value,OnGetDataFromWebMethodCompleted);
8 }
9 function OnGetDataFromWebMethodCompleted(data)
10 {
11 $get("webserviceDataDiv").innerHTML=data;
12 }
13 </script>
14
15 <input id="Text1" type="text" value="me_sa" />
16 <input id="Button3" type="button" value="GetDataFromWebService" onclick="getDataFromWebService();" />
17 <input id="Button4" type="button" value="getDataByServerMethod" onclick="getDataByServerMethod();" />
18 <div id="webserviceDataDiv">
19 </div>
2 //下面的脚本调用WebService取回数据显示在webserviceDataDiv
3
4 <script type="text/javascript">
5 function getDataByServerMethod()
6 {
7 PageMethods.ShowDetailData($get('Text1').value,OnGetDataFromWebMethodCompleted);
8 }
9 function OnGetDataFromWebMethodCompleted(data)
10 {
11 $get("webserviceDataDiv").innerHTML=data;
12 }
13 </script>
14
15 <input id="Text1" type="text" value="me_sa" />
16 <input id="Button3" type="button" value="GetDataFromWebService" onclick="getDataFromWebService();" />
17 <input id="Button4" type="button" value="getDataByServerMethod" onclick="getDataByServerMethod();" />
18 <div id="webserviceDataDiv">
19 </div>
本文转自钢钢博客园博客,原文链接:http://www.cnblogs.com/xugang/archive/2007/12/10/989615.html,如需转载请自行联系原作者