ASP.net Joyrock非同步應用樣本、JSON-RPC使用方法

來源:互聯網
上載者:User

ASP.net Joyrock非同步應用樣本、JSON-RPC使用方法

使用Joyrock 需要先引用Jayrock.dll,Jayrock.Json.dll兩檔案,另外在web頁面引入json.js檔案(不在同一個地方下載的json.js可用不了),

.net 後台檔案

 

using System;using System.Collections.Generic;using System.Linq;using System.Web;using Jayrock.Json;using Jayrock.JsonRpc;using Jayrock.JsonRpc.Web;namespace Exam.Jayrock{    public class Handler1 : JsonRpcHandler    {        ///         /// 未帶參數        ///         ///         [JsonRpcMethod("getstring1")]        public string getstring1()        {            return String.Format("Welcome to Jayrock by {0}!",DateTime.Now );        }        ///         /// 帶參數        ///         ///The string.        ///         [JsonRpcMethod("getstring2")]        public string getstring2(string str)        {            return String.Format("Welcome to Jayrock by {0}!", str);        }        [JsonRpcMethod("addEntity")]        public int addEntity(JsonObject ent)        {            new Entity("demo").addEntity(ent);            return 1;        }        [JsonRpcMethod("updateEntity")]        public int updateEntity(JsonObject ent)         {            new Entity("demo").updateEntity(ent);            return 1;        }        [JsonRpcMethod("delEntity")]        public int delEntity(int id)        {            new Entity("demo").delEntity(id);            return 1;        }        [JsonRpcMethod("getEntityList")]        public List getEntityList(string where)        {            return new Entity("demo").getEntityList(where);        }    }}

前台調用頁面

 

 

<script src="json.js" type="text/javascript"></script><script type="text/javascript" src="Handler1.ashx?proxy"></script><script> var demo = new Handler1(); function syncGetString1() { alert(demo.getstring1()); } function asyncGetString1() { demo.getstring1(function (val){ alert(val.result); }) } function syncGetString2() { var str = "voodooer"; alert(demo.getstring2(str)); } function asyncGetString2() { var str = "voodooer"; demo.getstring2(str,function (val) { alert(val.result); }) alert("我執行完了:)"); } function addEntity() { var Entity = Object(); Entity.Name = "voodoer"; Entity.Sex = "男"; var result = demo.addEntity(Entity); if (result > 0) { alert("添加實體成功!");} } function updateEntity() { var Entity = Object(); Entity.ID = 1; Entity.Name = "voodoer"; Entity.Sex = "男"; var result = demo.updateEntity(Entity); if (result > 0) { alert("更新實體成功!"); } } function delEntity() { var result = demo.delEntity(1); if (result > 0) { alert("刪除實體成功!"); } } </script>


 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.