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

今天想起接触WCF(Windows Communiction Foundation),开始弄个很小的例子。这里为大家讲用JQuery实现loading的功能
首页 新闻资讯 行业资讯 WCF初试,用JQuery实现loading的功能

1.建立WCF project

[[3561]]


默认的方法改为

复制


复制


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

  • 1.

  • 2.

  • 3.

  • 4.

  • 5.


就加一句

复制

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

2.加入MCF/MCF.aspx VIEW

复制


复制


< %@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>  < asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">     WCF  < /asp:Content> < asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">      < script src="http://www.cnblogs.com/Scripts/jquery-1.3.2.js" type="text/javascript">script>      < script language="javascript" type="text/javascript">         $(function() {          });      < /script>      <h2>         WCFh2>         <%using (Html.BeginForm())            { %>     < div id="divResult">         <h3>             Resulth3>         < fieldset>             < div id="divLoading">                 < img src='<%=Url.Content("~/Content/images/loader.gif")%>' alt="load" />                 please waiting...div>             < div id="DivResultData">             div>         < /fieldset>     < /div>     <%} %> < /asp:Content> 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.

  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

  • 18.

  • 19.

  • 20.

  • 21.

  • 22.

  • 23.

  • 24.

  • 25.

  • 26.

  • 27.

  • 28.

  • 29.

  • 30.

  • 31.


3.写Action,WCFController.cs

复制

public class WCFController : Controller      {          //          // GET: /WCF/          public ActionResult WCF()          {              return View();          }          [AcceptVerbs(HttpVerbs.Get)]          public ActionResult WCFTest()          {              string strResult=string.Empty;              WCFTest.Service1 testClient = new WCFTest.Service1();              strResult = testClient.GetData(1);              return Json(strResult);          }      }
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

  • 15.

  • 16.

  • 17.

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

复制

$(function() {            $.ajax({                type: "get",                url: "WCFTest",                datatype: "Json",                data: "",                complete: function() {                    $("#divLoading").css("display", "none");                },                success: function(data) {                    $("#DivResultData").html(data);                }            });        });
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  • 13.

  • 14.

4.调用WCF

复制

public ActionResult WCFTest()          {              string strResult=string.Empty;              WCFTest.Service1 testClient = new WCFTest.Service1();              strResult = testClient.GetData(1);              return Json(strResult);          }
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 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页面

15    2009-06-16 11:49:00    JQuery实现loading WCF