1$(document).ready(function(){
2 $.ajax({
3 url: 'ajaxfile.php',
4 type: 'get',
5 dataType: 'JSON',
6 success: function(response){
7 var len = response.length;
8 for(var i=0; i<len; i++){
9 var id = response[i].id;
10 var username = response[i].username;
11 var name = response[i].name;
12 var email = response[i].email;
13
14 var tr_str = "<tr>" +
15 "<td align='center'>" + (i+1) + "</td>" +
16 "<td align='center'>" + username + "</td>" +
17 "<td align='center'>" + name + "</td>" +
18 "<td align='center'>" + email + "</td>" +
19 "</tr>";
20
21 $("#userTable tbody").append(tr_str);
22 }
23
24 }
25 });
26});
1<?php
2
3include "config.php";
4
5$return_arr = array();
6
7$query = "SELECT * FROM users ORDER BY NAME";
8
9$result = mysqli_query($con,$query);
10
11while($row = mysqli_fetch_array($result)){
12 $id = $row['id'];
13 $username = $row['username'];
14 $name = $row['name'];
15 $email = $row['email'];
16
17 $return_arr[] = array("id" => $id,
18 "username" => $username,
19 "name" => $name,
20 "email" => $email);
21}
22
23// Encoding array in JSON format
24echo json_encode($return_arr);