01.
<html>
02.
<head>
03.
<style>
04.
05.
table, th, td {
06.
border: 1px solid black;
07.
}
08.
</style>
09.
</head>
10.
<body>
11.
<p id=
"demo"
></p>
12.
<script>
13.
14.
var
obj, dbParam, xmlhttp, myObj, x, txt =
""
;
15.
obj = {
"table"
:
"customer"
,
"limit"
:20 };
16.
dbParam = JSON.stringify(obj);
17.
xmlhttp =
new
XMLHttpRequest();
18.
xmlhttp.onreadystatechange =
function
() {
19.
if
(
this
.readyState == 4 &&
this
.status == 200) {
20.
myObj = JSON.parse(
this
.responseText);
21.
txt +=
"<table id='myTable' border='1'><tr><th>ชื่อ</th></tr>"
22.
for
(x
in
myObj) {
23.
24.
txt +=
"<tr id='w'><td id='a'><a href='#' onclick='test()'>"
+ myObj[x].cus_name +
"</a></td></tr>"
;
25.
26.
}
27.
txt +=
"</table>"
28.
document.getElementById(
"demo"
).innerHTML = txt;
29.
30.
}
31.
};
32.
xmlhttp.open(
"POST"
,
"json_demo_db_post.php"
,
true
);
33.
xmlhttp.setRequestHeader(
"Content-type"
,
"application/x-www-form-urlencoded"
);
34.
xmlhttp.send(
"x="
+ dbParam);
35.
36.
</script>
37.
</body>
38.
</html>