gpt4 book ai didi

javascript - 如何将变量发送到模态以显示从数据库php查询的值

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

我正在尝试将值发送到模态以从数据库中的表中查询并显示来自变量发送的 WHERE 子句的值我将其分配给具有“id”属性的模态我尝试用 javascript 将其保存在 cookie 中,但它显示随机值并且无法正常工作

这是我单击它以显示模式的链接,它在表中循环

<td>
<a data-toggle="modal" href="#gurantorname" id="'.$payment_row["GuarantorID"].'"> Guarantor Discount</a>
</td>

这是我的模式:

<!-- gurarntour modal-->
<div id="gurantorname" class="modal fade" tabindex="-1" data-width="400">
<div class="modal-header red">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title"> اسم الكفيل </h4>
</div>
<div class="modal-body">
<?php
if(isset($_COOKIE['myJavascriptVar'])) {
$_COOKIE['myJavascriptVar'];
echo $_COOKIE['myJavascriptVar'];
$guarantor_sth = $guarantorobj->getguarantorapplicationbyid($_COOKIE['myJavascriptVar']);
$guarantor_row = $guarantor_sth->fetch();
?>
<label class=" font-blue-dark text-center">
<strong>
<?php
echo $guarantor_row["GuarantorFirstNameAR"].' '.$guarantor_row["GuarantorSecondNameAR"] .' '.$guarantor_row["GuarantorThirdNameAR"].' '.$guarantor_row["GuarantorLastNameAR"] ;
?>
</strong>
</label>
<?php
}
?>
</div>
<div class="modal-footer text-right">
<a target="_blank" class="btn green" href="index.php?action=guarantorinfo&guarantorid=<?php echo $payment_row["GuarantorID"];?>" >معلومات الكفيل</a>
<button type="submit" data-dismiss="modal" class="btn btn-outline dark" >اخفاء</button>
</div>
</div>
<!--end of gurarntour modal-->

这是我的 javascript,它将 cookie 发送到模态:

<script type="text/javascript">
$('#gurantorname').on('show.bs.modal', function(e) {
var $modal = $(this),
esseyId = e.relatedTarget.id;
document.cookie = "myJavascriptVar ="+esseyId ;
alert(esseyId)
});
</script>

最佳答案

我认为当用户点击链接时你应该使用ajax

<a href="javascript:void(0)" class="link" id="'.$payment_row["GuarantorID"].'"> Guarantor Discount</a>

并在标签中添加 id 属性,用于通过 $ payment_row["GuarantorID"] 显示 guarantor_row

<label id="guarantor_row" class=" font-blue-dark text-center">

让我们创建 ajax 脚本

 $('body').on('click','.link',function(){
var id = $(this).attr('id');
$.ajax({
method: "POST",
url: "getguarantorapplicationbyid.php",
data: { id:id }
})
.done(function( json_response) {
var guarantor_row = $.parseJSON(json_response);
//set the data to modal and display
//guarantor_row.GuarantorFirstNameAR
//guarantor_row.GuarantorSecondNameAR
$('#guarantor_row').text(guarantor_row.GuarantorFirstNameAR+" "+guarantor_row.GuarantorSecondNameAR);
$('#gurantorname').modal('show');


});
});

getguarantorapplicationbyid.php

$guarantor_sth = $guarantorobj->getguarantorapplicationbyid($_POST['id']);
$guarantor_row = $guarantor_sth->fetch();
echo json_encode(guarantor_row);

关于javascript - 如何将变量发送到模态以显示从数据库php查询的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47258200/

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