gpt4 book ai didi

javascript - 使用 AJAX 更新我的列状态

转载 作者:行者123 更新时间:2023-12-03 03:07:50 26 4
gpt4 key购买 nike

如何在列状态中更新我的数据表?我尝试过使用这段代码,但它不起作用。我不知道要使用我的 AJAX 代码插入什么代码。我希望有人能帮助我解决这个问题。预先感谢您。

The right one. The wrong one.

   <script>
$(document).ready(function(){
$('#btn_edit').click(function(){
var id = $('#brand_id').val();
var brand_name = $('#brand_name').val();
var brand_status = $('#brand_status').val();

if (brand_status == "Available") {
brand_status = 1;
} else {
brand_status = 2;
}

$.ajax({
url : 'edit_brand.php',
method : 'POST',
data : {brand_name : brand_name, brand_status : brand_status, id : id},
success : function(response) {
$('#'+id).children('td[data-target=brand_name]').text(brand_name);
if (brand_status == 1) {
$('#'+id).children('td[data-target=brand_status]').append("<span class='label label-success'>Available</span>");
} else {
$('#'+id).children('td[data-target=brand_status]').append("<span class='label label-danger'>Not Available</span>");
}
$('#modal-edit').modal('toggle');
}
});
});
</script>

最佳答案

尝试像这样使用 post ajax 请求 -

$.post("edit_brand.php",
{
brand_name : brand_name, brand_status : brand_status, id : id
},
function(data, status){
$('#'+id).children('td[data-target=brand_name]').text(brand_name);
if (brand_status == 1) {
$('#'+id).children("<span class='label label-success'>Available</span>");
} else {
$('#'+id).children("<span class='label label-danger'>Not Available</span>");
}
$('#modal-edit').modal('toggle');
});

关于javascript - 使用 AJAX 更新我的列状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47089659/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com