Я создаю редактируемую строку в сценарии HTML, PHP и Java.[code]
[i][/i] [i][/i]
< /code> , и следующее приведено сценарий для обработки сохранения BTN (я включил обновление и удаление): < /p> $(document).ready(function() { $('[data-bs-toggle="tooltip"]').tooltip();
// Save changes $(document).on("click", ".save-btn", function() { let row = $(this).closest("tr"); let id = row.data("id"); let roomType = row.find(".room-type").text().trim(); let roomDesc = row.find(".room-desc").text().trim();
console.log("Saving:", roomType, roomDesc);
$.post("rooms.functions.php", { action: id ? "update" : "add", id, roomType, roomDesc }, function(response) { console.log("Raw Response:", response); // Log the raw response
// Only parse the response if it's valid JSON try { let res = JSON.parse(response); alert(res.message); if (res.status === "success" && !id) { row.attr("data-id", res.id); row.find("td:first").text(res.id); } } catch (e) { console.error("JSON Parse Error---> ", e); alert("Error processing request. Please check the console for details."); } }); });
// Delete room type $(document).on("click", ".delete-btn", function() { let row = $(this).closest("tr"); let id = row.data("id");
if (confirm("Are you sure you want to delete this room type?")) { $.post("rooms.functions.php", { action: "delete", id }, function(response) { console.log("Raw Response (Delete):", response); try { let res = JSON.parse(response); alert(res.message); if (res.status === "success") { row.remove(); } } catch (e) { console.error("JSON Parse Error:", e); alert("Error processing request. Check console for details."); } }); } });
// Add new row $("#addNew").click(function() { let newRow = $(`
New
[i][/i] [i][/i]
`); $("#roomTypeTable").append(newRow); }); }); < /code> Ниже приведен PHP, который управляет CRUD: < /p>