ASP.net Joyrock asynchronous application example, JSON-RPC usage

Source: Internet
Author: User

ASP.net Joyrock asynchronous application example, JSON-RPC usage

To use Joyrock, you must first reference the Jayrock. dll and Jayrock. Json. dll files, and introduce the json. js files on the web page (json. js files downloaded from different places cannot be used ),

. Net Background File

 

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 {////// Without parameters //////
 [JsonRpcMethod ("getstring1")] public string getstring1 () {return String. Format ("Welcome to Jayrock by {0 }! ", DateTime. Now );}////// With parameters //////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 );}}}
 

Frontend call page

 

 

  <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 ("I have finished execution :)");} Function addEntity () {var Entity = Object (); Entity. name = "voodoer"; Entity. sex = "male"; var result = demo. addEntity (Entity); if (result> 0) {alert ("Entity added successfully! ") ;}} Function updateEntity () {var Entity = Object (); Entity. ID = 1; Entity. name = "voodoer"; Entity. sex = "male"; var result = demo. updateEntity (Entity); if (result> 0) {alert ("Entity updated successfully! ") ;}} Function delEntity () {var result = demo. delEntity (1); if (result> 0) {alert (" Object deleted successfully! ") ;}}</Script> 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.