JSFiddle - React, Tailwind, and code Playground
HTML
<table cellspacing="0" border="1">
<tbody>
<tr>
<td><button type="button" class="ajaxPostUser">送信</button></td>
<td class="id">1</td>
<td class="name" contenteditable="true">太郎</td>
<td class="age" contenteditable="true">20</td>
<td class="count_likes">999</td>
<td class="json">{"id": 1, "name": "太郎", "age": 20, "count_likes": 999}</td>
</tr>
</tbody>
</table>
JavaScript
// 送信
$(document).on('click','.ajaxPostUser', function() {
const json = JSON.parse( $(this).closest('tr').find('td.json').text() );
ajaxPostUser( json );
});
function ajaxPostUser( json ){
// ajaxで json をPOSTする
$.ajax({
url : 'http...',
type : 'POST',
dataType: 'json',
data : json
}).done(function(responces) {
}).fail(function() {
});
}
// 編集
$(document).on('input','[contenteditable="true"]', function( evt ) {
editCol( evt );
});
function editCol( evt ) {
const $target = $( evt.target );
const $tr = $target.closest('tr');
const $td_json = $tr.find('td.json');
// 現在値
let json = JSON.parse( $td_json.text() || '{}' );
// 入力値
let inp_col;
let inp_val;
if ( evt.type === 'input' ) {
inp_col = $target.attr('class');
inp_val = $target.text().trim();
} else if ( evt.type === 'change' ) {
inp_col = $target.closest('td').attr('class');
inp_val = $target.val();
}
// 更新
json[inp_col] = inp_val;
$td_json.text( JSON.stringify(json, null , "\t") );
}