-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
72 lines (56 loc) · 1.86 KB
/
index.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
72
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<!-- Start of first page -->
<div data-role="page" id="foo">
<div data-role="header">
<h1>Foo</h1>
</div><!-- /header -->
<div role="main" class="ui-content">
<label for="text-1">Text input:</label>
<input name="text-1" id="text1" value="1" type="text">
<input type="submit" value="Submit Button" id="button1" />
<label for="text-2">Add a new quote:</label>
<input type="submit" value="Submit Button" id="button2" />
<!-- put the result here -->
<div id="result" class="functions"></div>
</div><!-- /content -->
<div data-role="footer">
<h4>Page Footer</h4>
</div><!-- /footer -->
</div><!-- /page -->
<script type="text/javascript">
$(document).bind('pageinit', function() {
alert("hello");
$.ajaxSetup ({
cache: false
});
$( "#button1" ).bind( "click", function(event, ui) {
var q = $("#text1").val();
alert("Click "+q);
var jsonUrl = "http://barretts.ecs.vuw.ac.nz:35030/quote/"+q;
alert("Fetching result from "+jsonUrl);
$.get(jsonUrl, function(data) {
alert(data.author);
$("#result").html("<p><b>"+data.author+" said "+data.text+"</b></p>")
}, 'json');
});
$( "#button2" ).bind( "click", function(event, ui) {
alert("Posting a new quote");
var jsonUrl = "http://barretts.ecs.vuw.ac.nz:35030/quote";
var newQuote = { "author" : "foo", "text" : "some text" };
$.post(jsonUrl,newQuote, function(data) {
alert("Added " + data.author + " " + data.text);
}, 'json');
});
});
</script>
</body>
</html>