Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

enter image description here

this is my view before triggering the modal

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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' " ;

>Solution :

It should be like this

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading