在我的ajax調用中,我想將每個key
作爲<td>
分配給$('#shelf .table thead tr')
中的單個行。這是我嘗試失敗的原因。將ajax數據val分配給表頭
AJAX:
function ajax_call($aff){
$.ajax({
url: 'fill_crosstab.php',
data: {action:$aff},
dataType: 'json',
success: function(data){
$('#shelf .table tbody').empty();
$('#shelf .table thead tr').empty();
for (var i = 0; i < key.length; i++) {
out += "<td>" + key[i] + "</td>";
}
$('#shelf .table thead tr').append(out + "</tr>");
if ($aff == "database") {
$.each(data, function(key, val) {
$('.dropdown-menu').append("<a class='dropdown-item' href='#'>" + val.Affiliation + "</a>");
});
// Bind the event now, after the html element has bend created.
$(".dropdown-menu a").on("click", function() {
var selText = $(this).text();
$('.shelf-header').empty();
$('.shelf-header').append(selText);
ajax_call(selText);
});
} else {
$.each(data, function(key, val) {
$('#shelf .table tbody').append("<tr><td>" + val.LAST + "</td><td>" + val.FIRST + "</td><td>" + val.MDC + "</td><td>" + val.RADIO + "</td><td>" + val.eMEDS + "</td><td>" + val.FireApp + "</td><td>" + val.P1 + "</td></tr>");
});
}
}
});
};
JSON數據:
[{"LAST":"JONE","FIRST":"MARY","MDC":"07\/23\/2003","RADIO":"08\/22\/2002","eMEDS":"02\/09\/2015","FireApp":"09\/11\/2012","P1":" "}]
您能否提供一些示例數據,並且可以更具體地瞭解它如何不起作用? –
添加了JSON數據 - 我正在尋找LAST,FIRST,MDC等...作爲我桌子的標題行。 – BarclayVision
定義第一個for循環的鍵是哪裏?我看不到這是什麼。 –