目前我已存儲的變量。這裏的目標是將它們變成PHP變量,以便我可以使用這些變量並將它們插入到我的數據庫中。傳遞數組JS變量到PHP在Javascript數組
這段代碼的問題是,AJAX的部分不工作。請讓我朝着正確的方向前進,因爲我對AJAX非常陌生。我確實嘗試瞭解他們,但仍然不太瞭解。沒有必要刷新頁面而無需刷新頁面。歡迎使用AJAX以外的方法。
這裏是我當前的代碼:
<button onclick="Bookings()">Book</button>
<script>
function Bookings() {
var t2Cells = document.getElementsByClassName("t2");
for (var i = 0; i < t2Cells.length; i++) {
var t2CellsIndex [i] = t2Cells[i].cellIndex
var t2CellsRow [i] = t2Cells[i].parentNode.rowIndex
//alert('Coordinates are: '+t2Cells [i].cellIndex+'x'+t2Cells [i].parentNode.rowIndex);
var tbl = document.getElementById("tblMain");
//alert (tbl.rows[0].cells[t2CellsIndex].innerHTML);
var studioSelected = tbl.rows[0].cells[t2CellsIndex].innerHTML
var Timeselected = tbl.rows[t2CellsRow].cells[0].innerHTML
$.ajax({
type: "POST",
url: 'bookingconfirm.php',
data: "studioSelected=" + studioSelect,
success: function(data) {
alert("success!");
}
});
}
}
</script>
<?php
//bookingconfirmed.php
if (isset($_POST['studioSelect'])) {
$uid = $_POST['studioSelect'];
//steps to insert into database.
那麼什麼沒有按」工作?你有任何錯誤?數據沒有被髮送到ajax文件? – Naruto
那麼,我理解它嗎?你設置數據鍵值對'studioSelected',但是檢查是否設置了't2CellsIndex'? –
什麼'的print_r($ _ POST)在Ajax目標文件''bookingconfirm.php'回報? – Thaillie