教程集 www.jiaochengji.com
教程集 >  jQuery  >  jQuery 插件  >  正文 rpc

rpc

发布时间:2014-08-04   编辑:jiaochengji.com
The is rpc(remote procedure call) client implementation based on JQuery. It creates an rpc object and adds ability to call them. It supports both xml and json rpc. The datatype support listing is coming soon. It is in early stage. It will not be upgraded
The is rpc(remote procedure call) client implementation based on jquery. It creates an rpc object and adds ability to call them. It supports both xml and json rpc. The datatype support listing is coming soon. It is in early stage. It will not be upgraded if you do not provide feedback . Please take a look at the code and let me know what you think :) .Synopsis$.rpc(url, dataType, onLoadCallback, version)

parameters:url - The url of the rpc server.dataType - It can be json or xml depending on the rpc server(optional, default:json).onLoadCallback - It is the method called when the rpc object is loadedfrom server response (optional).version - The rpc server version (optional).returns: - The rpc object parsed from the rpc server.How to use:After calling the $.rpc(your_server) you can get all the objects andmethods in that server.var server = $.rpc(your_server_url, "xml");It may take some time to load the server data. You can assign a loadcallback to add task whenthe server is loaded. Finally you can call the server functions like this,// call system.getCapabilities like this
server.system.getCapabilities(function(data){console.log(data)});
// or
server.yourObject.com.your.object.yourMethod(yourParams, callback);Note that this procedure is asynchronous. And callback functions arecalled when a task is done ..

And here is the demo code,<html>
<head>
       <title>demo</title>
       <!-- Add jquery library -->
       <script src="http://localhost/voip_support/misc/jquery.js"
type="text/javascript"></script>
       <!-- Add rpc plugin -->
       <script src="jquery.rpc.js" type="text/javascript"></script>
       <script>
               $(document).ready(function() {
                       window.rpc_plugins = $.rpc(
                               "xmlrpc.php" /* rpc server */
                               , "xml" /* say that our server is xml */
                               ,function(server) { /* this is
executed when the rpc server is prepared */
                                       /* The rpc server should have
a system object .. */
                                       if(!server || !server.system) {

$("#demo").change("Could not get the rpc object ..");
                                               return;
                                       }
                                       /* show the function list */
                                       var demo = $("#demo");
                                       var func = null;
                                       for(func in server.system) {
                                               demo.append(func + "(),");
                                       }
                               }
                       );
               });
       </script>
</head>
<body>
       <div id="demo">
       </div>
</body>
</html>

The above code will connect to the provided rpc server and list themethods in system object ..Please let me know if the above document is helpful. And let me knowif you have any suggestion.

您可能感兴趣的文章:
rpc
PHP XML-RPC 的使用
使用XML-RPC构造WebService
Python、PHP通过xml-rpc进行通信,xml-rpc中文的解决
使用go reflect实现一套简易的rpc框架
php rpc怎么实现?
Golang基础第五篇——golang的gRPC
订阅redis接收的json字符串斜杠_用 Golang 实现基于 Redis 的安全高效 RPC 通信
.Net远程方法调用研究
流行的php rpc框架详解

[关闭]
~ ~