jQuery rpc远程程序调用

联合创作 · 2023-10-02

这是基于 jQuery 的 rpc(远程程序调用)客户端实现。它创建了一个 rpc 对象并增加了调用它们的能力。它同时支持 xml 和 json rpc。数据类型支持列表即将推出。它处于早期阶段。如果你不提供反馈,它将不会被升级。请看一下代码并让我知道你的想法:) .

How to use:

After calling the $.rpc(your_server) you can get all the objects and
methods in that server.

var server = $.rpc(your_server_url, "xml");


It may take some time to load the server data. You can assign a load
callback to add task when
the 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 are
called 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 the
methods in system object ..

Please let me know if the above document is helpful. And let me know
if you have any suggestion.

浏览 1
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报