0
我有一個內聯編輯的數據表腳本,它的工作完美。麻煩的是,Ajax沒有發送數據到POST到PHP。我不知道該怎麼做,因爲我認爲我的代碼是正確的。內聯工作,輸入顯示當我按下編輯,當我按下保存它叫我test.php但它不發佈數據。這是我的js。Datatable內聯編輯不工作,因爲它應該
JS
function editRow(oTable, nRow) {
var aData = oTable.fnGetData(nRow);
var jqTds = $('>td', nRow);
jqTds[0].innerHTML = '<input type="text" class="form-control input-small" id="nume" value="' + aData[0] + '">';
jqTds[1].innerHTML = '<input type="text" class="form-control input-small" id="prenume" value="' + aData[1] + '">';
jqTds[2].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[2] + '">';
jqTds[3].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[3] + '">';
jqTds[4].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[4] + '">';
jqTds[5].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[5] + '">';
jqTds[6].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[6] + '">';
jqTds[7].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[7] + '">';
jqTds[8].innerHTML = '<a class="edit" href="">Save</a> <a class="cancel" href="">Cancel</a>';
}
function saveRow(oTable, nRow) {
var jqInputs = $('input', nRow);
oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
oTable.fnUpdate(jqInputs[5].value, nRow, 5, false);
oTable.fnUpdate(jqInputs[6].value, nRow, 6, false);
oTable.fnUpdate(jqInputs[7].value, nRow, 7, false);
oTable.fnUpdate('<a class="edit" href="">Edit</a>', nRow, 8, false);
oTable.fnDraw();
}
table.on('click', '.edit', function (e) {
e.preventDefault();
/* Get the row as a parent of the link that was clicked on */
var nRow = $(this).parents('tr')[0];
if (nEditing !== null && nEditing != nRow) {
/* Currently editing - but not this row - restore the old before continuing to edit mode */
restoreRow(oTable, nEditing);
editRow(oTable, nRow);
nEditing = nRow;
} else if (nEditing == nRow && this.innerHTML == "Save") {
/* Editing this row and want to save it */
saveRow(oTable, nEditing);
nEditing = null;
$.ajax({
type: 'POST',
url: 'test.php',
data: {num: $('#nume').val()},
success: function(data)
{
$("#content").html(data);
console.log(data);
}
});
} else {
/* No edit in progress - let's start one */
editRow(oTable, nRow);
nEditing = nRow;
}
});
檢查元素以查看使用數據表進行渲染後實際製作了哪些結構......此外,這不是一個常見問題嘗試使feedle得到更好的幫助。 – mansoor
結構很好,這裏是我按下編輯後生成的html ' – chris227