summaryrefslogtreecommitdiffstats
path: root/demo/helper.js
blob: cd3c226d2fbb432eb458dd98bdade1b33879ed27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

function Rpc(url, service) {
	this.url = url;
	this.service = service;
	this.id = 0;
	this.callAsync = function(method, data, dataFunc, errFunc) {
		this.id = this.id+1;
		var d =  {
			"service": this.service,
			"method": method,
			"id": this.id,
			"params": data
		};
		var ds = JSON.stringify(d);
		$.post(this.url, ds, function(data) {
			if (data.error == null)
				dataFunc(data.id, data.result);
			else if (errFunc)
				errFunc(data.id, data.error);
		}, "json");
		return this.id;
	}
}