-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_from_db_test.php
111 lines (91 loc) · 3.16 KB
/
read_from_db_test.php
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
<!DOCTYPE html>
<html>
<head>
<title>BORIS - DB Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<h1>Hello, world!</h1>
<div class="container">
<h2>GetCocktails.php</h2>
<span>
<?php
$base_url = 'http://localhost/ammi/php/';
$url = $base_url . 'getCocktailList.php';
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_HEADER, array(
'Content-Type: application/json',
'Accept: application/json'
)
);
$result = curl_exec($cURL);
$json_result = json_decode($result, true);
curl_close($cURL);
print_r($json_result);
?>
</span>
</div>
<div class="container">
<h2>Auslesen mit jQuery</h2>
<div class="btn-group">
<button type="button" class="btn btn-default" id="getCocktails">getCocktails</button>
<button type="button" class="btn btn-default" id="getIngredients">getIngredients</button>
<button type="button" class="btn btn-default" id="getRecipe">getRecipe</button>
<button type="button" class="btn btn-default" id="getTags">getTags</button>
</div>
<h2 id="outputHead"></h2>
<div id="outputBody"></div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
var
$getCocktails = $('#getCocktails'),
$getIngredients = $('#getIngredients'),
$getRecipe = $('#getRecipe'),
$getTags = $('#getTags'),
$outputHead = $('#outputHead'),
$outputBody = $('#outputBody'),
url = '',
handleRequest = function(event) {
console.log(event.currentTarget.id);
switch(event.currentTarget.id) {
case "getCocktails":
url = 'http://localhost/ammi/php/getCocktailList.php';
break;
case "getIngredients":
url = 'http://localhost/ammi/php/getIngredients.php';
break;
case "getRecipe":
url = 'http://localhost/ammi/php/getRecipe.php';
break;
case "getTags":
url = 'http://localhost/ammi/php/getTags.php';
break;
}
$.get(url, function(data) {
$outputHead.text(url);
$outputBody.text(JSON.stringify(data));
});
}
$getCocktails.on('click', handleRequest);
$getIngredients.on('click', handleRequest);
$getRecipe.on('click', handleRequest);
$getTags.on('click', handleRequest);
});
</script>
</body>
</html>