英文:
Passing data-id1 and data-id2 values to a modal in PHP using AJAX and JavaScript
问题
I want to pass double id (data-id1 and data-id2) values in modal.
when i try to do so i get only on data-id1 being pass the data-id2 doesn't get pass,
so the Modal popups with an empty table.
this is my view before triggering the modal
this is my HTML query:
<a class="openModal" data-id1="<?php echo htmlentities($result->requestitem_item); ?>" data-id2="<?php echo htmlentities($result->request_NUMBER); ?>" data-toggle="modal" href="#myModal"><input style="font-size:25px" type="text" name="itemserialno[]" value="" required>
and this is my script:
<script>
$('.openModal').click(function(){
var id1 = $(this).attr('data-id1');
var id2 = $(this).attr('data-id2');
$.ajax({url:"modalajax.php?id1="+id1+"&id2="+id2,cache:false,success:function(result){
$(".modal-content").html(result);
}});
});
</script>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog" style="width:50%">
<div class="modal-content">
</div>
</div>
</div>
Below is my Modal $_GET trigger:
$ID=$_GET['id1']??'';
$ID1=$_GET['id2']??'';
$sql = "SELECT * from itemTABLE where (itemTABLE_item ='$ID1' and itemTABLE_requestNUMBER ='$ID2') and itemTABLE_acceptance != 'Reject'";
英文:
I want to pass double id (data-id1 and data-id2) values in modal.
when i try to do so i get only on data-id1 being pass the data-id2 doesn't get pass,
so the Modal popups with an empty table.
this is my view before triggering the modal
this is my HTML query:
<a class="openModal" data-id1="<?php echo htmlentities($result->requestitem_item); ?>" data-id2="<?php echo htmlentities($result->request_NUMBER); ?>" data-toggle="modal" href="#myModal"><input style="font-size:25px" type="text" name="itemserialno[]" value="" required>
and this is my script:
<script>
$('.openModal').click(function(){
var id1 = $(this).attr('data-id1');
var id2 = $(this).attr('data-id2');
$.ajax({url:"modalajax.php?id1=&id2="+(id1&id2),cache:false,success:function(result){
$(".modal-content").html(result);
}});
});
</script>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog" style="width:50%">
<div class="modal-content">
</div>
</div>
</div>
Below is my Modal $_GET trigger:
$ID=$_GET['id1']??'';
$ID1=$_GET['id2']??'';
$sql = "SELECT * from itemTABLE where (itemTABLE_item ='$ID1' and itemTABLE_requestNUMBER ='$ID2') and itemTABLE_acceptance != 'Reject' " ;
答案1
得分: 2
这应该是这样的
$.ajax({
url: "modalajax.php?id1=" + id1 + "&id2=" + id2,
cache: false,
success: function(result) {
$(".modal-content").html(result);
}
});
英文:
It should be like this
$.ajax({
url: "modalajax.php?id1=" + id1 + "&id2=" + id2,
cache: false,
success: function(result) {
$(".modal-content").html(result);
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论