With a table based interface where users can update the rows by pressing a button. Perhaps there is a better way of doing this, without pressing a button, i.e. post on textarea/row change (could be a selectbox column). My requirement is that it's the LEAST amount of JavaScript possible, without being cryptic.
For example, could the code here be improved (assume an uptodate Firefox/Chrome browser), ideally without changing the HTML?
$(document).ready(function () {
$('button').click(function () {
var row = $(this).parent().parent();
row.css("background-color", "red");
var id = row.children(':nth-child(1)').text();
var note = row.find('textarea').val();
var data = {
json: JSON.stringify({
id: id,
note: note
})
};
$.ajax({
url: "/echo/json/",
type: "POST",
data: data,
contentType: "application/json"
}).done(function (d) {
console.log(d);
row.css("background-color", "green");
});
});
});
I want less code for the JavaScript and I was thinking how much effort if would be to remove the jQuery dependency entirely. Ashamedly it took me a long time to write that jQuery!