1
I use the Ajax code to do a post and update a record within the database. After that I wanted to load the page again without reloading the page. It refers to a product delivery screen. When I click on the delivery button a label with the situation of the product shows the text "Open" and after I click it should show "Delivered". The database update process works. So I would just like to change this situation text without refresh. There are ways to do this?
Ajax code:
$(".tabela-detalhes").on("click","#botao-entrega-volume",realizaEntrega);
function realizaEntrega() {
event.preventDefault();
var compra = $(this).parent().parent().find("#compra").val();
var sequencia = $(this).parent().parent().find("#sequencia").val();
var volume = $(this).parent().parent().find("#volume").val();
var dados = {
compra:compra,
sequencia:sequencia,
volume:volume
};
$(".entrega-volume").attr("name","entrega-volume").attr("value",JSON.stringify(dados));
$.post("controle/compras-volume-entrega.php",dados);
}
If an id is unique, it makes no sense to use
$(this).parent().parent().find("#compra").val()
. It was just enough$("#compra").val()
. I believe your HTML is invalid.– Sam
I think your comment has nothing to do with the question, isn’t it? Or I didn’t understand. This code works, I already use in the application. The id is generated dynamically within several rows in a table. Ai I have to know the values of some inputs that are a few levels up in table code.
– Bruno
I think you don’t understand rs... Look, an id should be unique on the page. For example, on the page there can be no other id
#compra
, then it makes no sense to search for Parent() to find an id if it can be found directly with$("#compra")
.– Sam