gpt4 book ai didi

javascript - Ajax 表行需要身份验证

转载 作者:行者123 更新时间:2023-11-30 20:23:46 25 4
gpt4 key购买 nike

我还有一个问题,因为上次大家都很好。如何在 ajax 中的表中设置特定行,仅当您登录时才显示?我在这里问这个是因为我在任何地方都找不到答案,而且我不知道如何自己做。所以,如果你们能解释一下,将不胜感激。

这是ajax表

    /* Add new Post table row */
function manageRow(data) {
var rows = '';
$.each( data, function( key, value ) {
rows = rows + '<tr>';
rows = rows + '<td>'+value.title+'</td>';
rows = rows + '<td>'+value.icon+'</td>';
rows = rows + '<td>'+value.user+'</td>';
rows = rows + '<td>'+value.details+'</td>';
rows = rows + '<td>'+value.created_at+'</td>';
rows = rows + '<td data-id="'+value.id+'">';
rows = rows + '<button data-toggle="modal" data-target="#edit-item" class="btn btn-warning edit-item">Edit</button> ';
rows = rows + '<button class="btn btn-danger remove-item">Delete</button>';
rows = rows + '</td>';
rows = rows + '</tr>';
});
$("tbody").html(rows);
}

如果您未登录,我希望看不到这两行。

rows = rows + '<button data-toggle="modal" data-target="#edit-item" class="btn btn-warning edit-item">Edit</button> ';
rows = rows + '<button class="btn btn-danger remove-item">Delete</button>';

希望大家帮帮我。提前谢谢你。

最佳答案

就我个人而言,我会选择这样的东西:

/* Add new Post table row */
function manageRow(data, isLoggedIn)
{
var rows = '';
$.each(data, function(key, value)
{
rows += '<tr>';
rows += '<td>' + value.title + '</td>';
rows += '<td>' + value.icon + '</td>';
rows += '<td>' + value.user + '</td>';
rows += '<td>' + value.details + '</td>';
rows += '<td>' + value.created_at + '</td>';
rows += '<td data-id="' + value.id + '">';

if (isLoggedIn)
{
rows += '<button data-toggle="modal" data-target="#edit-item" class="btn btn-warning edit-item">Edit</button> ';
rows += '<button class="btn btn-danger remove-item">Delete</button>';
}

rows += '</td>';
rows += '</tr>';
});

$("tbody").html(rows);
}

但是,这取决于您的安全顾虑,对于黑客来说,弄乱它并获得对这两个按钮的访问权限是微不足道的。

关于javascript - Ajax 表行需要身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51150738/

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