javascript
ASP.net Joyrock异步应用示例、JSON-RPC使用方法
使用Joyrock 需要先引用Jayrock.dll,Jayrock.Json.dll兩文件,另外在web頁面引入json.js文件(不在同一個地方下載的json.js可用不了),
.net 后臺文件
?
?| 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 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 ????{ ????????/// <summary> ????????/// 未帶參數 ????????/// </summary> ????????/// <returns></returns> ????????[JsonRpcMethod("getstring1")] ????????public string getstring1() ????????{ ????????????return String.Format("Welcome to Jayrock by {0}!",DateTime.Now ); ????????} ????????/// <summary> ????????/// 帶參數 ????????/// </summary> ????????///<param name="str">The string. ????????/// <returns></returns> ????????[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<jsonobject> getEntityList(string where) ????????{ ????????????return new Entity("demo").getEntityList(where); ????????} ????} }</jsonobject> |
前臺調用頁面
?
?
?| 1 |
<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>
?
轉載 :http://www.2cto.com/kf/201505/401062.html
轉載于:https://www.cnblogs.com/qinfenchuniao/p/7115066.html
總結
以上是生活随笔為你收集整理的ASP.net Joyrock异步应用示例、JSON-RPC使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 配置文件http://www.cnblo
- 下一篇: 第一个使用Spring Tool Sui