Passing data-id1 and data-id2 values to a modal in PHP using AJAX and JavaScript

59 views Asked by At

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.

enter image description here

this is my view before triggering the modal

enter image description here

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

There are 1 answers

0
Baekhan Sung On BEST ANSWER

It should be like this

$.ajax({
    url: "modalajax.php?id1=" + id1 + "&id2=" + id2,
    cache: false,
    success: function(result) {
        $(".modal-content").html(result);
    }
});