Resume 模态代码 Update profile -6ren">
gpt4 book ai didi

javascript - 在模态中传递一行的 id

转载 作者:行者123 更新时间:2023-11-30 00:07:33 24 4
gpt4 key购买 nike

我希望将特定行的 id 传递给模态

链接代码

<a href="#myModal" class="btn btn-default btn-small" id="custId" data-toggle="modal" data-id="<? echo $row['id']; ?>">Resume</a>

模态代码

<div id="myModal" class="modal fade" tabindex="-1" data-width="760">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Update profile</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="fetched-data"></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-default">Close</button>
<button type="submit" name="register" alt="Login" value="Submit" class="btn blue">Save changes</button>
</div>
</div>

脚本代码

<script>
$(document).ready(function(){
$('#myModal').on('show.bs.modal', function (e) {
var rowid = $(e.relatedTarget).data('id');
$.ajax({
type : 'post',
url : 'fetch.php', //Here you will fetch records
data : 'rowid='+ rowid, //Pass $id
success : function(data){
$('.fetched-data').html(data);//Show fetched data from database
}
});
});
});
</script>

fetch.php 的代码

<?php
$editId = $_POST['rowid'];
echo $editId;
?>

我应该得到 id 但我在模态中得到了未定义的值,谁能告诉我为什么会这样

最佳答案

试试这段代码

<a href="#myModal" class="btn btn-default btn-small ListId" id="custId" data-toggle="modal" data-id="<? echo $row['id']; ?>">Resume</a>

<div id="myModal" class="modal fade" tabindex="-1" data-width="760">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Update profile</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<span class='ShowData'> </span>
</div>
</div>
</div>

<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-default">Close</button>
<button type="submit" name="register" alt="Login" value="Submit" class="btn blue">Save changes</button>
</div>
</div>

脚本代码

<script>
$('.ListId').click(function()
{
var Id=$(this).attr('data-id');
$.ajax({url:"fetch.php?Id="+Id,cache:false,success:function(result)
{
$(".ShowData").html(result);
}});
});
</script>

fetch.php代码

$id=$_GET['Id'];
echo $id;

关于javascript - 在模态中传递一行的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37922402/

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