Код: Выделить всё
Live Table Data Edit
Table
$(document).ready(function(){
function fetch_data()
{
$.ajax({
url:"select.php",
method:"POST",
success:function(data){
$('#live_data').html(data);
}
});
}
fetch_data();
$(document).on('click', '#btn_add', function(){
var nome = $('#nome').text();
var preco = $('#preco').text();
if(nome == '')
{
alert("Enter Nome");
return false;
}
if(preco == '')
{
alert("Enter Preco");
return false;
}
$.ajax({
url:"insert.php",
method:"POST",
data:{nome:nome, preco:preco},
dataType:"text",
success:function(data)
{
alert(data);
fetch_data();
}
})
});
function edit_data(ref, 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);
}
});
}
$(document).on('blur', '.nome', function(){
var ref = $(this).data("ref1");
var nome = $(this).text();
edit_data(ref, nome, "nome");
});
$(document).on('blur', '.preco', function(){
var ref = $(this).data("ref2");
var preco = $(this).text();
edit_data(ref,preco, "preco");
});
$(document).on('click', '.btn_delete', function(){
var ref=$(this).data("ref3");
if(confirm("Are you sure you want to delete this?"))
{
$.ajax({
url:"delete.php",
method:"POST",
data:{id:id},
dataType:"text",
success:function(data){
alert(data);
fetch_data();
}
});
}
});
});
Код: Выделить всё
Код: Выделить всё
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/374 ... jax-jquery