WCF初试,用JQuery实现loading的功能

开发 开发工具
今天想起接触WCF(Windows Communiction Foundation),开始弄个很小的例子。这里为大家讲用JQuery实现loading的功能

1.建立WCF project

[[3561]]

默认的方法改为

  1. public string GetData(int value)  
  2.         {  
  3.             System.Threading.Thread.Sleep(5000);    //模拟等待  
  4.             return string.Format("You entered: {0}", value);  
  5.         } 

就加一句

  System.Threading.Thread.Sleep(5000);    //模拟等待

2.加入MCF/MCF.aspx VIEW

  1. < %@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> 
  2.  
  3. < asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
  4.     WCF  
  5. < /asp:Content> 
  6. < asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
  7.  
  8.     < script src="http://www.cnblogs.com/Scripts/jquery-1.3.2.js" type="text/javascript">script> 
  9.  
  10.     < script language="javascript" type="text/javascript"> 
  11.         $(function() {  
  12.         });  
  13.     < /script> 
  14.  
  15.     <h2> 
  16.         WCFh2> 
  17.         <%using (Html.BeginForm())  
  18.           { %> 
  19.     < div id="divResult"> 
  20.         <h3> 
  21.             Resulth3> 
  22.         < fieldset> 
  23.             < div id="divLoading"> 
  24.                 < img src='<%=Url.Content("~/Content/images/loader.gif")%>' alt="load" /> 
  25.                 please waiting...div> 
  26.             < div id="DivResultData"> 
  27.             div> 
  28.         < /fieldset> 
  29.     < /div> 
  30.     <%} %> 
  31. < /asp:Content> 

3.写Action,WCFController.cs

  1. public class WCFController : Controller  
  2.     {  
  3.         //  
  4.         // GET: /WCF/  
  5.         public ActionResult WCF()  
  6.         {  
  7.             return View();  
  8.         }  
  9.         [AcceptVerbs(HttpVerbs.Get)]  
  10.         public ActionResult WCFTest()  
  11.         {  
  12.             string strResult=string.Empty;  
  13.             WCFTest.Service1 testClient = new WCFTest.Service1();  
  14.             strResult = testClient.GetData(1);  
  15.             return Json(strResult);  
  16.         }  
  17.     } 

3.编写等待的JQuery实现loading..效果

  1. $(function() {  
  2.           $.ajax({  
  3.               type: "get",  
  4.               url: "WCFTest",  
  5.               datatype: "Json",  
  6.               data: "",  
  7.               complete: function() {  
  8.                   $("#divLoading").css("display", "none");  
  9.               },  
  10.               success: function(data) {  
  11.                   $("#DivResultData").html(data);  
  12.               }  
  13.           });  
  14.       }); 

4.调用WCF

  1. public ActionResult WCFTest()  
  2.         {  
  3.             string strResult=string.Empty;  
  4.             WCFTest.Service1 testClient = new WCFTest.Service1();  
  5.             strResult = testClient.GetData(1);  
  6.             return Json(strResult);  
  7.         } 

我不明白为什么我一把reference加入就可以使用WCF了,我看见网上很多文章很烦的要改一些东西啊,加一些代码啊,请达人解释

5.JQuery实现loading结果

[[3562]]

 [[3563]]

【编辑推荐】

  1. jQuery调用WCF服务传递JSON对象
  2. 学习jQuery必须知道的几种常用方法
  3. 用XML+XSLT+CSS+JQuery组建ASP.NET网站
  4. JQuery ID选择器中的不能包含特殊字符的处理
  5. 使用jQuery和PHP构建一个受Ajax驱动的Web页面
责任编辑:彭凡 来源: cnblogs
相关推荐

2010-02-22 14:28:35

WCF实现loadin

2010-02-25 13:35:27

WCF tcpTrac

2009-12-08 15:06:33

WCF传输DataSe

2022-02-17 14:34:10

viewport项目API

2010-02-23 09:51:32

WCF MTOM

2009-12-08 14:28:16

XTemplate +

2012-04-20 10:05:16

WCF

2009-11-09 16:25:24

WCF Data Co

2009-12-04 17:35:51

WCF 服务

2010-12-28 13:44:12

PHPXMLjQuery

2009-12-07 10:27:51

WCF分页

2009-07-03 09:44:39

实现RSS功能JSP技术

2011-05-16 09:30:30

jQueryWCF

2009-09-11 10:44:07

JavaScript实

2009-06-12 14:32:53

WCFJSON对象jQuery

2010-02-22 17:13:40

WCF会话状态

2010-02-26 10:56:06

WCF Stream

2012-12-28 14:32:34

Android开发Handler异步处理

2010-02-25 16:12:23

WCF IDispos

2010-02-24 12:49:39

WCF枚举
点赞
收藏

51CTO技术栈公众号