在使用ajax-jQuery處理一個小型搜索引擎並使用PHP函數後,我有一個數組JSON,並且我想處理這個表中的附加行,但是我感到困惑。如何創建表格或從JSON格式追加?
從查詢MySQL的JSON格式是好的,但我不知道如何處理數據生成表或附加在我的存在表。
我認爲這適用於每個JSON的每個元素,但我不能認爲。
注:我的JSON代碼是產生該這樣
...........
$jsonSearchResults = array();
while ($row = mysql_fetch_assoc($result)) {
$jsonSearchResults[] = array(
'clavemat' => $row['cve_mat'],
'tipomat' => $row['tipo_mat'],
'titulomat' => $row['titulo_mat'],
'autormat' => $row['autor_mat'],
'editmat' => $row['edit_mat'],
'success' => 'success'
);
}
echo json_encode ($jsonSearchResults);
表HTML
.........
<table class="busqueda">
<tr>
<th scope="col">Clave</th>
<th scope="col">Tipo</th>
<th scope="col">Título</th>
<th scope="col">Autor</th>
<th scope="col">Editorial</th>
</tr>
</table>
........
JSON CODE
[
{
"clavemat":"LICOELMCUS",
"tipomat":"Libro",
"titulomat":"Contabilidad",
"autormat":"Elias Flores",
"editmat":"McGraw Hill",
"success":"success"
},
{
"clavemat":"LICUDEMCNU",
"tipomat":"Libro",
"titulomat":"Curso java",
"autormat":"Deitel",
"editmat":"McGraw Hill",
"success":"success"
},
{
"clavemat":"REECMUMUNU",
"tipomat":"Revista",
"titulomat":"Eclipses",
"autormat":"Muy Interesante",
"editmat":"Muy interesante",
"success":"success"
},
{
"clavemat":"TEPLPLTENU",
"tipomat":"Tesis",
"titulomat":"Platanito Show",
"autormat":"Platanito",
"editmat":"Telehit",
"success":"success"
}
]
AJAX.JQUERY FILE
$.ajax({
type: "POST",
url: action,
data: dataSearch,
success: function (response) {
if (response[0].success == "success") {
alert("Si hay datos");
} else {
alert("No hay datos");
}
}
});
return false;
});
你可能想看看http://stackoverflow.com/q/7668413/1048572。這很容易。 – Bergi
謝謝,我會嘗試使用該代碼! – SoldierCorp