我想在json_encode的結果中顯示每個元素爲表格格式(見下文)。在這種情況下,jQuery代碼(在標題部分)和PHP代碼(在主體部分)在同一個PHP頁面中。如何顯示json_encode結果中的每個元素到PHP表格
任何人都可以幫助我嗎?
+-------+-------+
|fruit |price |
+-------+-------+
|apple |1.2 |
+-------+-------+
|pear |1.5 |
+-------+-------+
|orange |1.0 |
+-------+-------+
結果test.php的的:
[{"fruit":"apple","price":1.2},{"fruit":"pear","price":1.5},{"fruit":"orange","price":1.0}]
上面的代碼是通過利用json_encode test.php的()的結果。
jQuery的:
$(document).ready(function(){
$.ajax({
type: "POST",
dataType:"Json",
url: "test.php",
success: function(result){
}
});
});
只給定了你的需要,而不是你的問題。什麼阻礙你準確地編寫代碼?否則這很難回答。 – hakre