我的代码不起作用。当我更改gender
选择标记的值时,表不会更新。 Address
工作正常
$(document).on('blur', '.address', function(){
var id = $(this).data("id4");
var address = $(this).text();
edit_data(id, address, "address");
});
$(document).on('change', '.gender', function(){
var id = $(this).data("id5");
var gender = $(this).value();
edit_data(id, gender, "gender");
});
function edit_data(id, text, column_name) {
$.ajax({
url: "edit.php",
method: "POST",
data: {
id: id,
text: text,
column_name: column_name
},
dataType: "text",
success: function(data) {
alert(data);
}
});
}
edit.php:
<?php
include 'database/connect.php';
$id = $_POST["id"];
$text = $_POST["text"];
$column_name = $_POST["column_name"];
$sql = "UPDATE agents SET ".$column_name."='".$text."' WHERE id='".$id."'";
if (mysqli_query($conn, $sql))
{
echo 'Data Updated';
}
?>
select.php - 这是数据表来自
的地方<td class="address" data-id4="'.$row["id"].'" contenteditable>'.$row["address"].'</td>
<td>
<select class="gender" onchange="getval(this)" data-id5="'.$row["id"].'" >
<option value="Male" ' . ( $row["gender"]=='Male' ? 'selected' : '' ) . '>Male</option>
<option value="Female" ' . ( $row["gender"]=='Female' ? 'selected' : '' ) . '>Female</option>
</select>
</td>
答案 0 :(得分:0)
将var gender = $(this).value();
更改为var gender = $(this).val();