Reputation:
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);
}
});
Upvotes: 0
Views: 47
Reputation: 419
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>
Upvotes: 0
Reputation: 12391
change
<?php $_GET['id']; ?>
to
<?= $_GET['id'] ?>
or
<?php echo $_GET['id']; ?>
Upvotes: 1