将data-id1和data-id2的值通过AJAX和JavaScript传递到PHP模态框中

huangapple go评论65阅读模式
英文:

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.

将data-id1和data-id2的值通过AJAX和JavaScript传递到PHP模态框中

this is my view before triggering the modal

将data-id1和data-id2的值通过AJAX和JavaScript传递到PHP模态框中

this is my HTML query:

&lt;a class=&quot;openModal&quot; data-id1=&quot;&lt;?php echo htmlentities($result-&gt;requestitem_item); ?&gt;&quot; data-id2=&quot;&lt;?php echo htmlentities($result-&gt;request_NUMBER); ?&gt;&quot; data-toggle=&quot;modal&quot; href=&quot;#myModal&quot;&gt;&lt;input style=&quot;font-size:25px&quot; type=&quot;text&quot; name=&quot;itemserialno[]&quot; value=&quot;&quot; required&gt;

and this is my script:

&lt;script&gt;
  $(&#39;.openModal&#39;).click(function(){
      var id1 = $(this).attr(&#39;data-id1&#39;);
      var id2 = $(this).attr(&#39;data-id2&#39;);
      $.ajax({url:&quot;modalajax.php?id1=&amp;id2=&quot;+(id1&amp;id2),cache:false,success:function(result){
          $(&quot;.modal-content&quot;).html(result);
      }});
  });
&lt;/script&gt;

&lt;div id=&quot;myModal&quot; class=&quot;modal fade&quot; role=&quot;dialog&quot;&gt;
  &lt;div class=&quot;modal-dialog&quot; style=&quot;width:50%&quot;&gt;
    &lt;div class=&quot;modal-content&quot;&gt;

    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

Below is my Modal $_GET trigger:

$ID=$_GET[&#39;id1&#39;]??&#39;&#39;;
$ID1=$_GET[&#39;id2&#39;]??&#39;&#39;;

$sql = &quot;SELECT * from  itemTABLE where (itemTABLE_item =&#39;$ID1&#39; and itemTABLE_requestNUMBER =&#39;$ID2&#39;) and itemTABLE_acceptance != &#39;Reject&#39; &quot; ;

答案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: &quot;modalajax.php?id1=&quot; + id1 + &quot;&amp;id2=&quot; + id2,
    cache: false,
    success: function(result) {
        $(&quot;.modal-content&quot;).html(result);
    }
});

huangapple
  • 本文由 发表于 2023年5月25日 22:00:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76333143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定