4

I am trying to pass id from one script to another through javascript, i have been able to pass one id, but i am not able to understand how to pass 2 id

I have another id stored in $requestid variable, i wish to pass it in the following code so that i can call it in 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 anyone please tell how i can do so, without making much changes to original code

1
  • 2
    See $.ajax. Use data property. Also, use type to set the type - GET/POST... Commented Dec 31, 2015 at 6:23

2 Answers 2

2

You are very close.

Add another data attribute data-requestid to the same span element.

Get it the way you are getting id and pass it.

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>
Sign up to request clarification or add additional context in comments.

3 Comments

You could also retrieve data like $(this).data('id').
@R.Oosterholt, you are right. I have updated my answer.
"c_getinfo.php?Id="+Id+"&requestid="+requestid. This URL will be visible on console.So Use data: {key:value} and Method : POST in your ajax.
0

you can sent the $.post data by the $.get or $post method

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.