我正在使用php从数据库中检索数据:
<?php
while($trackResultRow = mysqli_fetch_assoc($trackResult)){?>
<a onclick="remove()"><span class="glyphicon glyphicon-thumbs-down pull-right"></span></a>
<li>
<a href="<?php echo $trackResultRow['track_path']?>">
<span id="username"><?php echo $trackResultRow['username']?></span> -
<span id="track"><?php echo $trackResultRow['track_name']?></span>
</a>
</li>
<hr>
<?php
}
?>
现在,当我点击链接时,它应该获取值并将其发送到Jquery函数(.ajax)以从表中删除记录而不刷新页面。
function remove()
{
var username = document.getElementById("username").value;
var track = document.getElementById("track").value;
//window.some_variable = '<?=$_GET[user]?>';
if(username && track)
{
$.ajax
({
type:'post',
url: 'delete_proc_admin.php',
data:
{
user_name:username,
user_track:track
},
success: function (response)
{
return alert (username +" "+ track);
}
});
}
return false;
}
但是JQuery功能不起作用。
我认为这是因为相同的ID,但我现在不知道如何修复我的代码。 有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
$(function() { // page load
$(".rem").on("click", function(e) { // the remove link
e.preventDefault(); // cancel link
var $link = $(this), // save for later
username = $(this).data("username"),
track = $(this).data("track");
$.ajax({
type: 'post',
url: 'delete_proc_admin.php',
data: {
user_name: username,
user_track: track
},
success: function(response) {
$link.closest('li').remove();
}
});
});
});
&#13;
<li>
<a href="#" class="rem"
data-userid="<?php echo $trackResultRow['username']?>"
data-track="<?php echo $trackResultRow['track_name']?>">
<span class="glyphicon glyphicon-thumbs-down pull-right"></span>
</a>
<a href="<?php echo $trackResultRow['track_path']?>">
<span><?php echo $trackResultRow['username']?></span> -
<span><?php echo $trackResultRow['track_name']?></span>
</a>
<hr/>
</li>
&#13;
答案 1 :(得分:0)
将链接本身传递给函数
<a onclick="remove(this)"></a>
function remove(link){
var username = link.getElementById("username");
}
答案 2 :(得分:0)
您可以将您的用户名和跟踪权限传递给删除功能并创建动态唯一ID,以使用用户名和跟踪选择容器
applyFIR :: Vector Double -> Vector Double -> Vector Double
applyFIR b x = generate (U.length x) help
where
revB = U.reverse b
bLen = U.length b
help i = let sliceLen = min (i+1) bLen
bSlice = U.slice (bLen - sliceLen) sliceLen revB
xSlice = U.slice (i + 1 - sliceLen) sliceLen x
in U.sum $ U.zipWith (*) bSlice xSlice
然后在你的删除功能
<div id="<?php echo $trackResultRow['username'] . $trackResultRow['track_name'] ?>">
<a onclick="remove('<?php echo $trackResultRow['username']?>',
'<?php echo $trackResultRow['track_name']?>')">