jQuery rpc遠(yuǎn)程程序調(diào)用
這是基于 jQuery 的 rpc(遠(yuǎn)程程序調(diào)用)客戶(hù)端實(shí)現(xiàn)。它創(chuàng)建了一個(gè) rpc 對(duì)象并增加了調(diào)用它們的能力。它同時(shí)支持 xml 和 json rpc。數(shù)據(jù)類(lèi)型支持列表即將推出。它處于早期階段。如果你不提供反饋,它將不會(huì)被升級(jí)。請(qǐng)看一下代碼并讓我知道你的想法:) .
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.
