0
我能夠使用json完成數據顯示但是如何將所有數據庫都打印到div或table?爲json發送的數據創建循環
JS
$(document).ready(function() {
$.ajax({
type : 'POST',
url : 'server.php',
dataType:"json",
success : function (data) {
alert(data[1].name);
}
});
});
PHP
<?php
$db = new PDO('mysql:host=localhost;dbname=Contact', 'root', '');
$statement=$db->prepare("SELECT * FROM myfeilds");
$statement->execute();
$results=$statement->fetchAll(PDO::FETCH_ASSOC);
$json=json_encode($results);
echo $json;
?>
你可以使用一個表庫(如datatables) –
與一個數據,並使用jquery來生成新的DOM –