How to pass PHP url variables to AJAX?

How could I pass PHP URL variables to AJAX so I can get the page content load in the same page ?? Here is an example of what I am trying to to do .. I am trying for example to get the “profile.php?id= to AJAX so that page content be be loaded .. However , I first started using a loop .. I dont know if that’s the right way to go about it ..

Below is the code

<div id="myDiv"><h2>Let AJAX change this text</h2></div>


<?php
require('../madscore/database/connect.php');
database_connect();
$query = "select * from Entertainers";
$result = $connection->query($query);
$row_count =$result->num_rows;

for($i = 1; $i <= $row_count; $i++)
  {
   $row = $result->fetch_assoc();
    //echo $i. "<br />";
   // echo $row['Name']."<br />";
   // echo $row['Profession']."<br />";
   // echo $row['Score']."<br />";

?>

<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","profile.php?id="<?php echo $row['ID'] ?>, true");
xmlhttp.send();
}
</script>




<?php  echo "<a href='/profile.php?id=".$row['ID']."' onclick='loadXMLDoc()'><img src ='../".$row['Picture']."' width='100' height='100' /> </a>"; } ?>

</body>
</html>

Leave a Reply

*

Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories