-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.php
74 lines (49 loc) · 1.72 KB
/
index.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
<html>
<head>
<title>AJAX jQuery Example with PHP MySQL</title>
<style type="text/css">
body{
font-family: Verdana, Geneva, sans-serif;
}
.container{
width: 50%;
margin: 0 auto;
}
table, tr, th, td {
border: 1px solid #e3e3e3;
padding: 10px;
}
</style>
</head>
<body>
<div class = "container" >
<h3><u>AJAX jQuery Example with PHP MySQL</u></h3>
<p><strong>Click on button to display users records from database</strong></p>
<div id="records"></div>
<p>
<input type="button" id = "getusers" value = "Fetch Records" />
</p>
</div>
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$(function(){
$("#getusers").on('click', function(){
$.ajax({
method: "GET",
url: "getrecords_ajax.php",
}).done(function( data ) {
var result= $.parseJSON(data);
var string='<table width="100%"><tr> <th>#</th><th>Name</th> <th>Email</th><tr>';
/* from result create a string of data and append to the div */
$.each( result, function( key, value ) {
string += "<tr> <td>"+value['id'] + "</td><td>"+value['first_name']+' '+value['last_name']+'</td> \
<td>'+value['email']+"</td> </tr>";
});
string += '</table>';
$("#records").html(string);
});
});
});
</script>
</body>
</html>