0

I want to send PHP value using ajax but it is not running .Please Help.

$.ajax({
             url:"getuser.php",
            type:"GET",
             data:{ id2: name2,id:<?php  $_GET['id']; ?> },
              success:function(data){
             $("#detail").html(data);

               }
              });
1
  • edit your code <?php echo $_GET['id']; ?> Commented Sep 21, 2016 at 8:42

2 Answers 2

1

change

<?php $_GET['id']; ?>

to

<?= $_GET['id'] ?>

or

<?php echo $_GET['id']; ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Not Working @Danyal Sandeelo
0

Code wise correction is As mentioned in above answers is change below line:

<?php $_GET['id']; ?>

to

<?php echo $_GET['id']; ?>

But make sure you will pass id as url parameter since you use $_GET method to assign value . For example:

http://localhost/YOUR_PROJECT_ROOT_DIRECTORY/filename.php?id=121

This must work.

Sample full functional code is below:

<a href="javascript:void(0)" onclick="test();">Click here</a>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
function test(){
    $.ajax({
             url:"getuser.php",
            type:"GET",
             data:{ id2: "1",id:<?php echo $_GET['id']?> },
              success:function(data){
                $("#detail").html(data);
               }
    })
}
</script>

2 Comments

Why id2 is 1.@Prajwal.
its just a number for reference used. if your java script has the variable with value assigned 'name2'(As per your example) u can just replace it as { id2: name2,id:<?php echo $_GET['id']; ?> }.

Your Answer

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