PHPRPC范例代码

Standard
1
2
3
4
5
6
7
8
//rpc_sayhi.php
require_once('./phprpc/php/phprpc_server.php');
function SayHi($name){
        return 'Hi! '.$name;
}
$phprpc=new PHPRPC_Server();
$phprpc->add('SayHi');
$phprpc->start();
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
/*sayhi.js*/
 $(document).ready(function(){
         $('#submit').click(
                 function(){
                         $('#waiting').show();
                         $('.clear_rs').trigger("click");
                         getRPC();
                 }
         );
         $('.clear_rs').click(
                 function(){
                         $('.clear_rs').hide();
                         $('#hi_name_p').hide('slow');
                 }
         );
 }
 )
 function getRPC(){
         var rpc = new PHPRPC_Client('http://yemaosheng.com/rpc_sayhi.php', ['SayHi']);
                 rpc.SayHi($('#q').val(),function(result){
                      $('#hi_name_p,.clear_rs').show('slow');
                           $('#waiting').hide();
                           $('#hi_name_p').html(result);
                   });
   }
1
2
3
4
5
6
7
8
<! index.html-->
<script src="jquery.js" type="text/javascript"></script>
<script src="phprpc_client.js" type="text/javascript"></script>
<script src="sayhi.js" type="text/javascript"></script>
<input id="q" maxlength="20" name="q" size="20" type="text" />
<input id="submit" maxlength="20" name="submit" size="20" type="button" value="Say Hi!" />
<img id="waiting" style="display:none;" src="http://bawbaw.hu.googlepages.com/indicator.gif" alt="" />  
<input class="clear_rs" style="display:none;" maxlength="20" name="clear_rs2" size="20" type="button" value="Clear" />

PHPRPC官方网站: http://www.phprpc.org

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.