WCF初試,用JQuery實現loading的功能
作者:跛腳的胖子
今天想起接觸WCF(Windows Communiction Foundation),開始弄個很小的例子。這里為大家講用JQuery實現loading的功能
1.建立WCF project
默認的方法改為
- public string GetData(int value)
- {
- System.Threading.Thread.Sleep(5000); //模擬等待
- return string.Format("You entered: {0}", value);
- }
就加一句
System.Threading.Thread.Sleep(5000); //模擬等待
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">
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);
- }
- }
3.編寫等待的JQuery實現loading..效果
- $(function() {
- $.ajax({
- type: "get",
- url: "WCFTest",
- datatype: "Json",
- data: "",
- complete: function() {
- $("#divLoading").css("display", "none");
- },
- success: function(data) {
- $("#DivResultData").html(data);
- }
- });
- });
4.調用WCF
- public ActionResult WCFTest()
- {
- string strResult=string.Empty;
- WCFTest.Service1 testClient = new WCFTest.Service1();
- strResult = testClient.GetData(1);
- return Json(strResult);
- }
我不明白為什么我一把reference加入就可以使用WCF了,我看見網上很多文章很煩的要改一些東西啊,加一些代碼啊,請達人解釋
5.JQuery實現loading結果
【編輯推薦】
責任編輯:彭凡
來源:
cnblogs