Menu

[r190]: / phprpc_2.1 / sample / phprpc.html  Maximize  Restore  History

Download this file

116 lines (111 with data), 3.0 kB

  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
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<html>
<head>
<script type="text/javascript" src="../js/compressed/xmlhttprequest.js"></script>
<script type="text/javascript" src="../js/compressed/full/phprpc_client.js"></script>
<script type="text/javascript">
phprpc_client.create('rpc', true);
rpc.onready = function () {
rpc.inc.ref = true;
}
rpc.use_service('server.php');
rpc.encrypt = 2;
rpc.add_callback = function (result, args) {
if (result instanceof phprpc_error) {
alert(result.errstr);
}
else {
document.getElementById('sum').value = result;
}
return true;
}
sub_callback = function (result) {
if (result instanceof phprpc_error) {
alert(result.errstr);
}
else {
document.getElementById('diff').value = result;
}
return true;
}
rpc.hello_callback = function (result, args, output) {
if (result instanceof phprpc_error) {
alert(result.errstr);
alert(output);
}
else {
alert(output);
}
return true;
}
rpc.inc_callback = function (result, args) {
if (result instanceof phprpc_error) {
alert(result.errstr);
}
else {
document.getElementById('inc').value = args[0];
}
return true;
}
window.onload = function () {
var add = document.getElementById('add');
add.onclick = function () {
var a = document.getElementById('a').value;
var b = document.getElementById('b').value;
if (rpc.ready) {
rpc.add(a, b);
}
else {
alert('rpc not ready!');
}
}
var sub = document.getElementById('sub');
sub.onclick = function () {
var c = document.getElementById('c').value;
var d = document.getElementById('d').value;
if (rpc.ready) {
rpc.sub(c, d, sub_callback);
rpc.sub(c, d, function (result) { alert(result); } );
}
else {
alert('rpc not ready!');
}
}
var hello = document.getElementById('hello');
hello.onclick = function () {
if (rpc.ready) {
rpc.hello(document.getElementById('name').value);
}
else {
alert('rpc not ready!');
}
}
var inc = document.getElementById('inc');
inc.onclick = function() {
if (rpc.ready) {
var n = inc.value;
rpc.inc(n);
}
else {
alert('rpc not ready!');
}
}
}
</script>
</head>
<body>
<input type="text" id="a" /> +
<input type="text" id="b" /> =
<input type="text" id="sum" />
<input type="button" id="add" value="calc" />
<br />
<input type="text" id="c" /> -
<input type="text" id="d" /> =
<input type="text" id="diff" />
<input type="button" id="sub" value="calc" />
<br />
<input type="text" id="name" />
<input type="button" id="hello" value="hello" />
<br />
<input type="button" id="inc" value="1" />
</body>
</html>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.