-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.html
40 lines (35 loc) · 1.07 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<title>jQuery Ajax Example with JSON Response</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(':submit').on('click', function() { // This event fires when a button is clicked
var button = $(this).val();
$.ajax({ // ajax call starts
url: 'json_list.json', // JQuery loads serverside.php
data: '', // Send value of the clicked button
dataType: 'json', // Choosing a JSON datatype
success: function(data) // Variable data constains the data we get from serverside
{
$('#incidents').html(''); // Clear #wines div
for (var i in data) {
$('#incidents').append('Incident: ' + data[i].Incident + '</br>');
}
}
});
return false; // keeps the page from not refreshing
});
});
</script>
</head>
<body>
<form method="post" action="">
<button value="all" type="submit">Get Incidents!</button>
</form>
<div id="incidents">
<!-- Javascript will print data in here -->
</div>
</body>
</html>