I have a<table> i can click on a <td> and a Dialog shows up.Now i can enter an String and submit it.The submit writes the String into my Database and displays it on the <td>Element.
What i want to do, is that if i click again on the same <td>-Element and i enter a different Text, this should overwrite the old Text in the Database and `.
What i am looking for is how to get that working with Ajax.`
$(document).ready(function() {
var activeTD;
$(".td_test").click(function() {
$("#bModal").modal('show');
activeTD = this;
if ($(activeTD).html()) {
// The cell has stuff in it
$("input[name=getdata]").val($(activeTD).html());
}
else {
// The cell is empty
$("input[name=getdata]").val("");
}
});
$("#ajaxtest").submit(function(ev) {
var name = $("#ajaxtest").serialize();
ev.preventDefault();
$.ajax({
type:"POST",
processData:false,
url:"InsertServlet",
dataType: "text",
data: name
})
.done(function(data){
$(activeTD).text(data);
});
$("#bModal").modal('hide');
});
$("input[name=deleteData]").click(function(e){
var name = $("#ajaxtest").serialize();
e.preventDefault();
$.ajax({
type:"POST",
processData:false,
datatype:"text",
url:"DeleteServlet",
data:name
})
.done(function(data){
$(activeTD).text("");
});
$("#bModal").modal('hide');
});
});
This is what i have so far, a working DELETE und SUBMIT button. Hope someone can help :)
Aucun commentaire:
Enregistrer un commentaire