Comments (2)
index.php
<?php
include('HproseHttpServer.php');
define("SEX_UNKNOWN", 0);
define("SEX_MALE", 1);
define("SEX_FEMALE", 2);
define("SEX_INTERSEX", 3);
class User {
var $name;
var $sex;
var $birthday;
var $age;
var $married;
function User($name, $sex, $birthday, $age, $married) {
$this->name = $name;
$this->sex = $sex;
$this->birthday = $birthday;
$this->age = $age;
$this->married = $married;
}
}
function hello($name) {
return 'Hello ' . $name;
}
function sum() {
$args = func_get_args();
$sum = 0;
foreach ($args as $i) {
$sum += $i;
}
return $sum;
}
function swapKeyAndValue(&$trans) {
$trans = array_flip($trans);
return $trans;
}
function getUserList() {
$userlist = array(
new User("Amy", SEX_FEMALE, new HproseDate(1983, 12, 3), 26, true),
new User("Bob", SEX_MALE, new HproseDate(1989, 6, 12), 20, false),
new User("Chris", SEX_UNKNOWN, new HproseDate(1980, 3, 8), 29, true),
new User("Alex", SEX_INTERSEX, new HproseDate(1992, 6, 14), 17, false)
);
return $userlist;
}
$server = new HproseHttpServer();
$server->addFunction('hello');
$server->addFunction('sum');
$server->addFunction('swapKeyAndValue');
$server->addFunction('getUserList');
$server->setDebugEnabled(true);
$server->setCrossDomainEnabled(true);
$server->start();
?>
demo.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta content="Content-Type" equiv="text/html; charset=utf-8" />
<script type="text/javascript" src="hprose.js"></script>
</head>
<body>
<script type="text/javascript">
var client = new HproseHttpClient('http://127.0.0.1/index.php', ['hello', 'sum', 'swapKeyAndValue', 'getUserList']);
client.hello("World!", function(result) {
console.log(result);
});
client.sum(1, 3, 5, function(result, args) {
console.log(result);
console.log(JSON.stringify(args));
});
client.swapKeyAndValue({"Jun":1, "Feb":2, "Mar": 3}, function(result, args) {
console.log(JSON.stringify(result));
console.log(JSON.stringify(args));
});
client.getUserList(function(result) {
console.log(JSON.stringify(result));
});
</script>
</body>
</html>
from hprose.
Thank you very much for your reply,very detailed.
2013-11-26
bingchengcool
发件人:andot [email protected]
发送时间:2013-11-25 20:52
主题:Re: [hprose] do you have any demos for js client? (#6)
收件人:"andot/hprose"[email protected]
抄送:"libingcheng"[email protected]
index.php
name = $name; $this->sex = $sex; $this->birthday = $birthday; $this->age = $age; $this->married = $married; } } function hello($name) { return 'Hello ' . $name; } function sum() { $args = func_get_args(); $sum = 0; foreach ($args as $i) { $sum += $i; } return $sum; } function swapKeyAndValue(&$trans) { $trans = array_flip($trans); return $trans; } function getUserList() { $userlist = array( new User("Amy", SEX_FEMALE, new HproseDate(1983, 12, 3), 26, true), new User("Bob", SEX_MALE, new HproseDate(1989, 6, 12), 20, false), new User("Chris", SEX_UNKNOWN, new HproseDate(1980, 3, 8), 29, true), new User("Alex", SEX_INTERSEX, new HproseDate(1992, 6, 14), 17, false) ); return $userlist; } $server = new HproseHttpServer(); $server->addFunction('hello'); $server->addFunction('sum'); $server->addFunction('swapKeyAndValue'); $server->addFunction('getUserList'); $server->setDebugEnabled(true); $server->setCrossDomainEnabled(true); $server->start(); ``` ?>demo.html
<script type="text/javascript" src="hprose.js"></script> <script type="text/javascript"> var client = new HproseHttpClient('http://127.0.0.1/index.php', ['hello', 'sum', 'swapKeyAndValue', 'getUserList']); client.hello("World!", function(result) { console.log(result); }); client.sum(1, 3, 5, function(result, args) { console.log(result); console.log(JSON.stringify(args)); }); client.swapKeyAndValue({"Jun":1, "Feb":2, "Mar": 3}, function(result, args) { console.log(JSON.stringify(result)); console.log(JSON.stringify(args)); }); client.getUserList(function(result) { console.log(JSON.stringify(result)); }); </script>—
Reply to this email directly or view it on GitHub.
from hprose.
Related Issues (13)
- hprose for cpp can use?
- How to client can Hprose use https? HOT 1
- 请问这个与phprpc的区别? HOT 2
- Request support for unix socket HOT 4
- 建议添加类似于WCF的Session会话模式 HOT 1
- How to use the hprose for cpp?
- There is a serious unserialize bug in Java version. HOT 3
- value of field java.sql.Date mismatch HOT 3
- Value of Character cannot be null HOT 1
- request support golang HOT 2
- hprose java 方法发布或存问题(访问不到) HOT 1
- Hprose for python2,字典参数有问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hprose.