Pass variable through javascript

I am trying to pass id from one script to another via javascript, I was able to pass one id, but I can not figure out how to pass 2 id

I have another identifier stored in the $ requestid variable, I want to pass it in the following code so that I can call it on the c_getinfo.php page

<span class='ListId' data-id="<?php echo $row1['id'];?>">

<script>
  $('.ListId').click(function(){
        var Id=$(this).attr('data-id');
        $.ajax({url:"c_getinfo.php?Id="+Id,cache:false,success:function(result){
            $(".ShowData").html(result);
        }});
    });
</script>

can someone tell me how I can do this without making big changes to the source code.

+4
source share
2 answers

You are very close.

Add another data attribute data-requestidto the same span element.

Get this as you get the id and pass it on.

You are done.

Corrected Code:

<span class='ListId' data-id="<?php echo $row1['id'];?>" data-requestid="<?php echo $requestid?>">

<script>
  $('.ListId').click(function(){
        var Id=$(this).attr('data-id');
        var requestid=$(this).data('requestid');
        $.ajax({url:"c_getinfo.php?Id="+Id+"&requestid="+requestid,cache:false,success:function(result){
            $(".ShowData").html(result);
        }});
    });
</script>
+2
source

$.post $.get $post

$.post('c_getinfo.php', { field1: "id", field2 : "requestid"}, 
        function(returnedData){
             console.log(returnedData);
    });
0

Source: https://habr.com/ru/post/1622308/


All Articles