-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsubstitutes.html
71 lines (70 loc) · 1.72 KB
/
substitutes.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Substitutes-demo</title>
<link rel="stylesheet" href="css/style.css">
<script src="javascript/zepto.min.js"></script>
</head>
<body>
<h1>Substitute Interface Using "JSON"</h1>
<hr>
<h2>GET</h2>
<p><input onclick="getUserName()" type="button" value="Get user name"> <span id="username"></span></p>
<p><input onclick="getUserAge()" type="button" value="Get user age"> <span id="userage"></span></p>
<p><input onclick="getUserBio()" type="button" value="Get user bio"> <span id="userbio"></span></p>
<hr>
<h2>POST</h2>
<p>Says something:</p>
<p><textarea id="message" cols="100" rows="5"></textarea></p>
<p><input onclick="submitMessage()" type="button" value="Submit"></p>
<hr>
<h2>How to do this?</h2>
<p>We just add rules to ".justreq" as follow:</p>
<pre>
{
...
"rules": [
{
"url": "api/post.do",
"subs": "api/post.json"
},
{
"url": "api/user.do",
"subs": "api/user.json"
}
]
}
</pre>
<p class="tips">These json files of this example are located in ".jr/subs/api/"</p>
<script>
function getUserName(){
$.get('http://127.0.0.1:8000/api/user.do', function(user){
$('#username').text(user.name);
});
}
function getUserAge(){
$.get('http://127.0.0.1:8000/api/user.do', function(user){
$('#userage').text(user.age);
});
}
function getUserBio(){
$.get('http://127.0.0.1:8000/api/user.do', function(user){
$('#userbio').text(user.bio);
});
}
function submitMessage(){
var data = {
message: $('#message').val()
};
$.post('http://127.0.0.1:8000/api/post.do', data, function(res){
if (res.ok) {
alert('Submit success!');
} else {
alert('Submit failed!');
}
});
}
</script>
</body>
</html>