Sample of Get JSON to Table

因AJAX不能跨domain取資料...所以getJSON的部分需要帶入相對位置喔~

<html>
<head>
<title>Parsing JSON From PHP Using jQuery</title>
<script src="/HR/js/jquery/jquery-1.3.2.min.js" type="text/javascript">
</script>
</head>
<body>
<a href="#" id="loaduserdata">User Data</a>
<table id="userdata" border="1">
<thead>
<th>First Name</th>
<th>Last Name</th>
</thead>
<tbody></tbody>
</table>
<script>
$(document).ready(function(){
});
$("#loaduserdata").click(function(){
$("#userdata tbody").html("");
$.getJSON(
"/HR/JsonRequest?event=8",
function(data){
$.each(data.items, function(i,n){
var tblRow =
"<tr>"
+"<td>"+n.mkey+"</td>"
+"<td>"+n.mvalue+"</td>"
+"</tr>"
$(tblRow).appendTo("#userdata tbody");
});
}
);
});
</script>
</body>
</html>

這個網誌中的熱門文章

Bash判斷參數是否存在

Node.js package : forever