好的,所以基本上我要做的是获取从 MySQL 插入返回的“slot_id”的创建 id 值。(有效),然后我尝试使用 slot_id 的返回值设置新的 tr 的 id。正在设置变量 slot_id 我想我只是用错了。这是代码。如果我添加一个 console.log(slot_id); 在成功时它返回值。
$('#add_slot').click(function(e){
var slot_id;
date = $("#slot_date").val();
start_time = $("#slot_start").val();
end_time = $("#slot_end").val();
speaker_id = $("#speaker").val();
speaker = $("#speaker option:selected").text();
event_id = $("#event_id").val();
last_row = $("tr:last").hasClass('odd');
$.ajax({
type: 'POST',
url: 'ajax/process_slot.php',
data: {
date: date,
start_time: start_time,
end_time: end_time,
speaker_id: speaker_id,
event_id: event_id
},
success: function(response){
var $bodyresp=$(response);
var resp = $bodyresp.filter("#response").text();
slot_id = $bodyresp.filer("#slotid").text();
/// slot_id is the problem child. Why is it when I access it below to set the tr id value to slot_' + slot_id ......
$("#flash_message").html(resp);
$('#mask , .popup').fadeOut(300 , function() {
$('#mask').remove();
});
}
});
if(last_row === false){
$("#slot_table").find('tbody')
.append($('<tr id="slot_'+ slot_id +'" class="odd">')
.append($('<td>' + date + '</td>' + '<td>' + start_time + '</td>' + '<td>' + end_time + '</td><td>'+ speaker+'</td><td><a class="delete_row" href="#delete_row">Delete Row</a></td>')
)
);
}else {
$("#slot_table").find('tbody')
.append($('<tr id="slot_'+slot_id+'" class="even">')
.append($('<td>' + date + '</td>' + '<td>' + start_time + '</td>' + '<td>' + end_time + '</td><td>'+ speaker+'</td><td><a class="delete_row" href="#delete_row">Delete Row</a></td>')
)
);
}
e.preventDefault();
})